2 ms·
It might be safer to loop in reverse: for (let i=setTimeout(''); i--; i>=0) { clearTimeout(i); } That way if the optimiser decides not to opti
by dspillett 9y ago
It might be safer to loop in reverse:
for (let i=setTimeout(''); i--; i>=0) {
clearTimeout(i);
}
That way if the optimiser decides not to optimise such that the termination condition doesn't call setTimeout() every iteration, you don't end up with an infinite loop because the result of setTimeout('') ends up incrementing in-step with the value of i.
That advantage of browser support, assuming it was internal support and not tacked on in the dev-tools, would be that they could implement a toggle so the timers can be reactivated after you've finished checking what they were getting in the way of.
[note: interval timers may need to be considered as well as timeout timers, unless they use the same ID counter with not type checking so either can be turned off by either clearTimeout() or clearInterval() - again that may be an implementation detail that varies between browsers]
- Jakob 9y agoGood catch on the reverse loop, you’re right.