作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我刚刚浏览了 jQuery 的代码并遇到了函数合并。我查看了这个函数的代码:
merge: function( first, second ) {
var len = +second.length,
j = 0,
i = first.length;
while ( j < len ) {
first[ i++ ] = second[ j++ ];
}
// Support: IE<9
// Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists)
if ( len !== len ) {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
},
现在,如果您查看代码,您将遇到以下 if
检查:
if ( len !== len )
这在某种程度上对我来说没有意义,这个检查到底是为了什么,它在做什么?
len
上面几行定义的很清楚,像这样:
var len = +second.length;
那么为什么有人要检查 len !== len
呢?这在某种程度上对我来说没有意义。有人可以解释吗?
最佳答案
这是对 NaN
的检查(正如@Jonathan 的评论中正确指出的那样)。来自优Mozilla documentation :
NaN
compares unequal (via ==, !=, ===, and !==) to any other value -- including to anotherNaN
value. UseNumber.isNaN()
orisNaN()
to most clearly determine whether a value isNaN
. Or perform a self-comparison:NaN
, and onlyNaN
, will compare unequal to itself.
关于javascript - jQuery合并函数中的if条件令人困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968391/
很抱歉新手的问题,但是: 我最近才发现“=”运算符不只是处理对象/等等。值(value),也是引用。这很酷,但我认为这对变量来说是不一样的,它不会在存储整数或 float 的变量之间创建引用。后来我觉
我是一名优秀的程序员,十分优秀!