I am new to C++, and I'm trying to port some javascript scripts while learning the new language.
I am trying to find solutions to use callbacks like javascript, especially like the js-signals library
Below is a script in javascript. Can it be converted to C++? How? If no, what is the best solution?
Javascript
var ns = {
_callback: null,
setUpdate: function(callback) {
ns._callback = callback;
},
update: function() {
// do some default things
ns._callback();
}
};
ns.setUpdate(function() {
console.log("I'm Changed"); // will be: std::cout << "I'm Changed\n";
});
C++
namespace ns {
// ??
};
// ns::setUpdate(??);