I need to invoke some function given number of times through given delays. How should I do - declare variable for timer and pass it to invoking function for stopping timer in some moment or in loop (n times) invoke setTimeout once ( or some another approach to skeep delay time once) or other.Thanks.
edit to fix syntax eror
var timerID = null;
var n = 5;
this.timerID = setInterval(function(){
funcToInvoke(n,timerID){
if(invokeNumber == n){
clearInterval(timerID);
return;
}
else { do something}
}
},delay)
setInterval(or a "recursive" call tosetTimeout) is better than a loop that invokessetTimeoutseveral times.funcToInvokeis a syntax error (or parsed as an invocation + a code block, which is not what you want). Please fix it, and notice that thethiskeyword in the interval-function does not point to your object.