I have some javascript using the Revealing Module Pattern as shown below. It accepts a callback function that it later invokes. I want that callback function to then be able to call functions defined in the class, but it's not working.
window.MyClass = function() {
var self = this,
start = function (callback) {
callback(self);
},
cancel = function() {
console.log('Cancel invoked');
};
return {
start: start,
cancel: cancel
};
};
var myCallbackFunction = function(instance) {
instance.cancel(); // Error: instance.cancel is not a function
};
var obj = new window.MyClass();
obj.start(myCallbackFunction);
I can rework this sample into the Revealing Prototype Pattern and it works as expected, so my question is can I get this working using RMP, or is it just a limitation of this pattern?
Thanks, Roger