Want to store current context to a variable using this code , can any one help me what I am missing here?
Because in handling event, getting $this as this of window object.
var Modal = (function() {
$this = this;
var el = '.modal';
return {
init: function() {
$(window).on('showModal', function(e, data) {
$this.getData(data.controller, data.action, data.id);
});
},
getData: function(controller, action, id) {
var html = $.ajax({
url: '/' + controller + '/' + action + '/' + id ? id : '',
async: false
}).responseText;
this.render(html);
},
render: function(html) {
$(el).html(html);
$(el).modal();
this.event();
},
event: function() {
}
};
})();
Thanks For Help!