You are forgetting to use prototype
. Your close method should be:
CustomModal.prototype.close = function() {
dialog.close(this);
};
The way you have it written, close()
is a "static" method. Whereas, with prototype
, it is a "class" method. That's why this
isn't referencing what you expect. Using the prototype chain, this
will reference the instantiated object.
UPDATE: Here is an example of how to close the modal from your main code that will work, but, it requires that you refactor your show()
method.
define(['plugins/dialog', 'knockout'], function (dialog, ko) {
var CustomModal = function () {
this.msg = ko.observable(" Please Wait...");
};
CustomModal.prototype.show = function () {
return dialog.show(this);
};
CustomModal.prototype.close = function () {
dialog.close(this);
};
return CustomModal;
});
// from your main code, you use it like this
var modal = new modalBusy();
modal.show();
// then, whenever you want to close it
modal.close();