class Frame {
constructor() {
this.init();
}
init(){
setTimeout(function(){this.secondFunction()}, 2000); // DOES NOT WORK
}
secondFunction(){
}
}
I am trying to call a function of a class from another function of same class. When I call it directly with "this.secondFunction()" then it works fine. But when I move it insode of a setTimeout or a JQuery function, it does not work and throws error "this.secondFunction is not a function". I think this is because the "this" changes to timer object when I call it from setTimeout. What's the correct way to call the function in this scenario?