I have declared an object with variables and methods.
Here it is simplified
var myObj = {
myTimer: null,
startTimer: function(){
clearTimeout(myObj.myTimer);
myObj.myTimer = setTimeout("myObj.myFunction()", 250);
},
myFunction: function(){
alert('Hi');
}
};
After startTimer is invoked, the following errors is printed to the console
Uncaught ReferenceError: myFunction is not defined
Uncaught ReferenceError: startTimer is not defined
How can i solve this?
There was actually nothing wrong with my code, although it could probably be more pretty.
The problem was how i was calling the methods, and not within the object itself.