You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array.prototype._map = function(callbackfn, thisArg) {
let O = new Object(this);
if (this === null || this === undefined) {
throw new TypeError("Cannot read property 'map' of null or undefined");
}
if (Object.prototype.toString.call(O) !== "[object Array]") {
throw new TypeError("this is not a Array!")
}
let len = O.length >>> 0; // 向右移动0位, 相当于Math.floor
if (Object.prototype.toString.call(callbackfn) !== "[object Function]") {
throw new TypeError(callbackfn + "is not a function!")
}
let T = thisArg ? thisArg : undefined
let A = new Array(len);
let k = 0;
while(k < len) {
if (k in O) {
let kValue = O[k];
let mappedValue = callbackfn.call(T, kValue, O);
A[k] = mappedValue;
}
k++;
}
return A;
}
[2,3,4]._map(r => r * 2) // [4,6,8]
The text was updated successfully, but these errors were encountered: