方法一
let _map=function(a,f){
return a.reduce((sum,value,idx,a)=>{
sum.push(f(value,idx,a));
return sum;
},[]);
}
let a=[1,2,3];
let b=_map(a,value=>value*value);
console.log('rlt:',b);
方法二
Array.prototype._map=function(f,thisArg){
let self = this || thisArg;
console.log(thisArg);
return self.reduce((sum,value,idx,self)=>{
sum.push(f.bind(self)(value,idx,self));
return sum;
},[]);
}
let a=[1,2,3];
let b=a._map(value=>value*value);
console.log('rlt:',b);