I want to do this either by pure javascript or any sort of console in a browser or whatever.
Is it possible?
Thanks
Further explanations:
I want to debug a library that does animations. I want to know if there’s multiple timers created if there are multiple objects being animated.
As others have mentioned,
setTimeoutdoesn’t spawn a thread. If you want a list of all the timeout ids (so you can cancel them, for example) then see below:I don’t think you can get a list of all timeout ids without changing the code when they are called.
setTimeoutreturns an id—and if you ignore it, then it’s inaccessible to your JavaScript. (Obviously the interpreter has access to it, but your code doesn’t.)If you could change the code you could do this:
…Making sure that
timeoutIdis declared in global scope (perhaps by usingwindow.timeoutId = []).Just off the top of my head, but to reimplement
setTimeoutyou’d have to do something like this:This isn’t tested, but it gives you a starting point. Good idea, molf!
Edit: aularon’s answer gives a much more thorough implementation of the above idea.