I don't know how to deal properly with this case. I have a Javascript object like this:
var myClass = {
init : function(){
$("button").on("click" , this.func1);
},
func1: function(){
// do stuffs
this.func2();
},
func2: function(){
// do stuffs
}
}
myClass.init();
When I initialize my class for binding event there's no problem. In the init function, the value of this
is the class itself, so I can call their methods without problem.
Take into account that when a button is clicked, I executed func1
. I found the problem inside the function func1
because in this case the value of this
is the button that was pressed, so when I try this.func2
I get Uncaught TypeError: this.func2 is not a function
.
How I deal with this kind of problem? I'm sure that there is a standar way to solve this problem but I don't know it.
Thanks !!