I would like to delay my while loop on each iteration. I tried the following:
var o = 1;
while(o<4){
setTimeout("setupAnimation(o)",2000);
//setupAnimation(o); //<--this works but everything happens att the same time
o++;
}
I also tried to write it like this, which didn’t work either:
var o = 1;
function repeatMe(){
setupAnimation(o);
o++;
setTimout('repeatMe()',1000);
}
Any suggestions?
evalis slow, hard to debug and has potential security problems (depending on where the data comes from). Don’t use it. (Passing a string tosetTimeoutusesevalby proxy.)Pass a function to
setTimeoutinstead. You’ll need to use a closure to capture the current value ofofor the function you pass.You should probably also use a
forloop here instead of awhileloop. The syntax is clearer.