I'm trying to achieve the task shown by the example code below, but get this error :
Uncaught TypeError: this.myFunction is not a function
I know i'm doing something wrong but don't know the right way to do it : how can i access the 'this' object inside a Jquery listener ?
Thanks in advance !
var MyClass = function () {
return {
myFunction: function () {
console.log('Do something');
},
myOtherFunction: function() {
$('#myButton').on('click', function () {
this.myFunction(); // here i get the error
});
}
}
}