I am trying to migrate some JavaScript functionality to OOP JavaScript like this:
function Test(parameters) {
this.containerID = parameters['containerID'];
....
this.navNext = $('#' + this.containerID + ' #test');
...
}
Test.prototype = {
constructor: Test,
...
init: function () {
...
this.navNext.on('click', function (event) {
...
this.showNext(); //here is the issue
});
...
},
showNext: function () {
...
}
};
Then I am instantiating new instance like follows:
test = new Test({'containerID':'test_id'});
test.init();
But when I click on the "next button" or ($('#test_id '#test' element) I am getting the following error:
Uncaught ReferenceError: showNext is not defined
I guess in the on jQuery function this.showNext() is pointing to selected element showNext() function, not my prototype function.
Could anyone give me an advice how to fix this behavior?