可能重复:
What good does zero-fill bit-shifting by 0 do? (a >>> 0)x >>> 0做什么?
我一直试图出我的项目的一些函数式编程的概念和我念叨Array.prototype.map
,这在ES5是新的,看起来像这样的:
Array.prototype.map = function(fun) {
"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
res[i] = fun.call(thisp, t[i], i, t);
}
}
return res;
};
什么我不知道就是为什么它做t.length >>> 0
。因为它似乎没有做任何事情。 x >>> 0 //-> x
! (只要x是一个数字,显然)
此外,请注意,我不知道按位运算符是如何工作的。
和许多其他的http://stackoverflow.com/questions/1822350/ http://stackoverflow.com/questions/1474815/ http://stackoverflow.com/questions/1385491/的http:// stackoverflow.com/questions/3348438/只有当找到第一个> _>时才能很容易地找到它们。 – kennytm 2010-11-02 19:16:50
@KennyTM〜好的重复,如果你知道事物的名字是...;) – jcolebrand 2010-11-02 19:31:09