Ten*_*man 17 javascript jquery nan
我刚刚浏览了jQuery的代码并遇到了函数merge.我检查了这个函数的代码:
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;
},
Run Code Online (Sandbox Code Playgroud)
现在,如果您查看代码,您将看到以下if检查:
if ( len !== len )
Run Code Online (Sandbox Code Playgroud)
这在某种程度上对我没有意义,究竟是什么检查,它在做什么?
len 明确定义了几行,如下:
var len = +second.length;
Run Code Online (Sandbox Code Playgroud)
那么为什么有人会检查一下len !== len呢?这在某种程度上对我没有意义.有人可以解释一下吗?