我正在查看Mozilla的代码,它为Array添加了一个过滤方法,它有一行代码让我很困惑.
var len = this.length >>> 0;
Run Code Online (Sandbox Code Playgroud)
我以前从未见过用于JavaScript的>>>.
它是什么,它做了什么?
可能重复:
零填充位移0有什么用?(a >>> 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 …Run Code Online (Sandbox Code Playgroud) 这是Mozilla的Array.prototype.indexOf中的Mozilla代码
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt)
{
var len = this.length >>> 0; // What does ">>>" do?
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from): Math.floor(from);
if (from < 0)from += len;
for (; from < len; from++)
{
if (from in this && this[from] === elt)return from;
}
return -1;
};
}
Run Code Online (Sandbox Code Playgroud)
我不明白一些语法.
">>>"在上面的代码中做了什么?