I have a quick question about using recursive setTimeOut
recursively and a clearTimeOut
that get called somewhere else.
On rare cases, will there ever gonna be a bug where clearTimeOut
doesn't actually stop the loop? Is it possible that the timeOutID
get changes into a new value and clearTimeout
is called on the old value?
Here is the code:
timeOutID = 0;
function timeOutRecusive() {
timeOutID = setTimeout('timeOutRecusive();', 1000);
}
function killTimeOutRecusive() {
clearTimeout(timeOutID);
}
//when page started.
start() {
timeOutRecusive();
}
//When a button is press, calls killTimeOutRecursive();
EDIT: I have some typo in my code. It should be 'timeOutID' instead of clockID. clearTimeOut should be 'clearTimeout' (using its built-in)