I’m a little stuck with trying to set a setTimeout to a function call that is made using the .call() method.
Basically, I’ve got an array of function references, am then stepping through them one by one and calling them with a certain setTimeout interval. The first function fires aok, but the second doesn’t and I’m getting an error in the js console that I don’t understand – the error is –
Uncaught TypeError: Object 73 has no method ‘call’
The code:
function scene1(){
alert("boo");
}
function scene2(){
alert("boo2");
}
var arrAnimation = [];
arrAnimation[0] = scene1;
arrAnimation[1] = scene2;
//step through the array
for (var i = 0; i < arrAnimation.length; i++){
setTimeout(arrAnimation[i],3000).call();
}
Any help would be really appreciated.
Dan
You don’t need to use
call– all you need to do is pass the function tosetTimeoutand it will be run automatically:FYI on the error itself –
setTimeoutreturns a number as a handle, which lets you cancel the timeout later if that is something you need. Numbers don’t have acallfunction.