setTimeout能否返回0作为id? [英] Can setTimeout ever return 0 as the id?
本文介绍了setTimeout能否返回0作为id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写一张支票,看看超时是否有效。我想这样做:
I am writing a check to see if a timeout is active. I was thinking of doing this:
var a = setTimeout(fn, 10);
// ... Other code ... where clearTimeout(a) can be called and set to null
if (a != null)
{
// do soemthing
}
我想知道a是否有可能是0。那个案子我会用 a!== null
I was wondering if it would ever be possible that a will be 0. In that case I would use a !== null
推荐答案
首先: 0与null不同,(0 == null)在每种情况下都为false';
First: 0 isn't the same as null, (0 == null) would be false in every case';
如果你想对某些东西测试'a':define首先'a'然后将settimeout分配给'a'。然后检查'a'的类型。如果它'未定义',则计时器尚未触发
if you want to test 'a' against something: define 'a' first and later assign the settimeout to 'a'. then check against the type of 'a'. If its 'undefined', the timer hasn't triggered yet
这篇关于setTimeout能否返回0作为id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文