最近我在jQuery源代码中找到了一个奇怪的行(最新版本1.9.1,Sizzle包,第129行funescape函数):
funescape = function( _, escaped ) {
var high = "0x" + escaped - 0x10000;
// NaN means non-codepoint
return high !== high ? // <--- LINE 129
escaped :
// BMP codepoint
high < 0 ?
String.fromCharCode( high + 0x10000 ) :
// Supplemental Plane codepoint (surrogate pair)
String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
};
Run Code Online (Sandbox Code Playgroud)
high !== high比较的原因是什么?它显然看起来return escaped永远不会被执行.或者我会错过什么?
参考: https ://github.com/jquery/sizzle/blob/master/sizzle.js#L129
我一般不喜欢微基准测试.但这一个有一个非常有趣的结果.
http://ernestdelgado.com/archive/benchmark-on-the-floor/
它表明这Math.floor是在Javascript中计算楼层的最慢方式.~~n,n|n,n&n全部为快.
这看起来非常令人震惊,因为我希望在今天的现代浏览器中实现Javascript的人会是一些相当聪明的人.
对于其他方法无法做到的事情,地板是否重要?有没有理由使用它?