Eventuali duplicati:
What good does zero-fill bit-shifting by 0 do? (a >>> 0)Cosa fa x >>> 0?
Ho provato alcuni concetti di programmazione funzionali in un mio progetto e stavo leggendo Array.prototype.map
, che è nuovo in ES5 e si presenta come questo:
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;
};
Quello che mi chiedo è per questo che sta facendo t.length >>> 0
. Perché non sembra fare nulla. x >>> 0 //-> x
! (purché x sia un numero, ovviamente)
Inoltre, si noti che non so come funzionano gli operatori bit a bit.
e un sacco di altri http://stackoverflow.com/questions/1822350/ http://stackoverflow.com/questions/1474815/ http://stackoverflow.com/questions/1385491/ http: // stackoverflow.com/questions/3348438/ Questi sono facili da trovare solo quando si trova il primo> _>. – kennytm
@KennyTM ~ Buoni duplicati se sai quali sono i nomi delle cose ...;) – jcolebrand