直接上代码
Array.prototype.map = function (callback, thisArg) {
let O = Object(this)
let k = 0;
let len = O.length >>> 0
let arr = [];
while (k < len) {
if (k in O) {
let item = callback.call(thisArg, O[k], k, this) // 传递给回调函数的参数
arr.push(item)
}
k++
}
return arr;
}
function parseInt(string, radix) {
// 1 0 string为1到9 radix为0 则将cur解析为十进制数据 --- 1
// 2 1 radix范围为2-36 --- NaN
// 3 2 3不能用2进制表示 --- NaN
console.log(cur, index)
...
}
let newArr = Array.prototype.map.call([1, 2, 3], parseInt); // [1,NaN,NaN]