Is there a way to check if a var is using setInterval()?

前端 未结 6 889
失恋的感觉
失恋的感觉 2020-12-12 16:30

For instance, I am setting an interval like

timer = setInterval(fncName, 1000);

and if i go and do

clearInterval(timer);
         


        
6条回答
  •  春和景丽
    2020-12-12 16:58

    Well you can do

    var interval = setInterval(function() {}, 1000);
    interval = clearInterval(interval);
    if (typeof interval === 'undefined'){
    ...
    }
    

    but what are you actually trying to do? clearInterval function is an always success function and it will always return undefined even if you call it with a NaN value, no error checking in there.

提交回复
热议问题