tags:

views:

62

answers:

2

For instance, I am setting an interval like

timer = setInterval(fncName, 1000);

and if i go and do

clearInterval(timer);

it does clear the interval but is there a way to check that it cleared the interval? I've tried getting the value of it while it has an interval and when it doesn't but they both just seem to be numbers.

+1  A: 

The return values from setTimeout and setInterval are completely opaque values. You can't derive any meaning from them; the only use for them is to pass back to clearTimeout and clearInterval.

There is no function to test whether a value corresponds to an active timeout/interval, sorry! If you wanted a timer whose status you could check, you'd have to create your own wrapper functions that remembered what the set/clear state was.

bobince
thank you for your confirmation
chadley
+2  A: 

There is no direct way to do what you are looking for. Instead, you could set timer to false every time you call clearTimeout:

var timer = setInterval(fncName, 1000);

clearTimeout(timer);
timer = false;

Now, timer will either be false or have a value at a given time, so you can simply check with

if (timer)
    ...
Casey Hope
this is what i planned to do if no was the answer to my question. i wrote something similar:`var stopInterval = function(varname) { clearInterval(); varname = false; } var isRunning = function(varname) { return !!varname; }`i know this exactly wont work because varname will probably be a string, thus making it always true, but its the idea that works for me. your way would work as well but people beware that setInterval() gives the var a numeric value and if it could come out as 1 or 0 meaning t/f.
chadley
eh, i guess formatting doesnt work in comments... my bad. does anyone know how to format code in a comment or is that just not allowed at all?
chadley