I
Ivo
Hi,
somewhere in my code a timeout is set in a function:
var timer = null;
function foo( n ) {
var delay = 500;
// do stuff with n
timer = window.setTimeout( 'foo(' + ( ++n ) + ');', delay );
}
Now elsewhere in another function, called during a totally unrelated event,
this time-out needs to be canceled. Not a problem:
if( timer ) { window.clearTimeout( timer ); }
But before erasing the values, I would like to store the string and delay
parameters used when setting the last timer, to be exact if I know the value
of n, I can at some time after the cancelling restart the timer at the point
it was canceled. Saving this information is of course possible in
traditional ways with more code in the function, more global variables, etc.
but is there a way to extract the info simply from the setTimeout where it
resides and which I am dealing with anyway? Such functionality could highly
simplify lots of work.
hth
ivo
somewhere in my code a timeout is set in a function:
var timer = null;
function foo( n ) {
var delay = 500;
// do stuff with n
timer = window.setTimeout( 'foo(' + ( ++n ) + ');', delay );
}
Now elsewhere in another function, called during a totally unrelated event,
this time-out needs to be canceled. Not a problem:
if( timer ) { window.clearTimeout( timer ); }
But before erasing the values, I would like to store the string and delay
parameters used when setting the last timer, to be exact if I know the value
of n, I can at some time after the cancelling restart the timer at the point
it was canceled. Saving this information is of course possible in
traditional ways with more code in the function, more global variables, etc.
but is there a way to extract the info simply from the setTimeout where it
resides and which I am dealing with anyway? Such functionality could highly
simplify lots of work.
hth
ivo