利用reduce 模仿map原理

Array.prototype.myMap = function(callback){
  const self = this;
  return self.reduce((prev,next,index)=>{
    prev.push(callback(next,index,self))
    return prev
  },[])
}

 

posted @ 2020-07-14 20:09  心之所指,行之所至  阅读(176)  评论(0)    收藏  举报