I have a function that sets bunch of setTimeout functions. All functions are added to Array funcs; nevertheless, when I try to stop them using stopplay().clearTimeout the array has no values.
How to access those functions and clearTimeout on them?
var funcs = new Array();
function playWithDelay(){
for (var i = 0; i < PlayDatesArray.length; i++) {
funcs[i] = createfunc(i);
}
for (var j = 0; j < PlayDatesArray.length; j++) {
funcs[j]();
}
}
function createfunc(i) {
return function() {
setTimeout(function(){
//my function
}, i*1500);
};
}
function stopplay(){
alert(this.funcs.count);
for (var i = 0; i< funcs.count; i++){
//things I tried
var tmpFunction = funcs[i];
//funcs[i].splice(i, 1);
clearTimeout(tmpFunction);
clearTimeout(funcs[i]);
funcs[i]=tmpFunction;
}
}