Why can't I refer to a method of a JavaScript object by using "this"?
Like for example in open();
method - why can't I call this.init();
?
var myModule = {
//Initialize dek. Append html structure to the body
init: function() {
if (!$('.mwdek').length) {
var dek = $(tpl);
dek.find('.d-nav-close').on('click', function(e) {e.stopPropagation();e.preventDefault();
this.destroy();
});
dek.appendTo('body');
}
//var dek = $('.mwdek');
},
//Opens deck, makes it visible
open: function() {
if (!$('.mwdek').length) {
this.init();
}
$('.mwdek').addClass('active');
},
//Removes deck html from the page
destroy: function(messages) {
$('.mwdek').remove();
},
//Pass in header text content
setHeaderText: function() {
}
};