Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clearTimeout without ID

Is there any way to clear setTimeout() if it doesn't have an explicit ID? The problem is I'm not allowed to change some code that already ran and set the timers without any handler.

Does JS set 'anonymous handlers' to them? Are these timers stored anywhere accessible? Can I get any of those properties (the function the timer is about to call? the time it'll be called?)

like image 701
djspark Avatar asked Nov 29 '22 10:11

djspark


1 Answers

Nope, you can't without a reference. You could try something REALLY hacky (don't do this! it's just an illustration of hackyness) to clear all timeouts:

for(var i=0; i<100000; i++) clearTimeout(i);

but again that's not foolproof and well beyond hacky.

Solution? Fight be able to change the source, so you can do this properly - or see if you can override the function creating the timer.

like image 164
Nick Craver Avatar answered Nov 30 '22 23:11

Nick Craver