【发布时间】:2015-09-07 03:46:57
【问题描述】:
在阅读 D3.js 的源代码时,我看到了 x >= x 模式。如果是为了检测数字中的NaN,为什么不直接isNaN(x)或者x == x呢?
Source, where I encountered it:
d3.min = function(array, f) {
var i = -1, n = array.length, a, b;
if (arguments.length === 1) {
while (++i < n) if ((b = array[i]) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = array[i]) != null && a > b) a = b;
} else {
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
}
return a;
};
【问题讨论】:
-
@FelixKling 谢谢!我实际上是在寻找一些带注释的源代码,但似乎没有:annotated copy of d3.js source code like the one for jQuery?
标签: javascript d3.js coding-style nan