废话不多说直接上代码 // 重构forEach() // 传入一个函数fn作为参数 Array.prototype.myforEach=function(fn) { // 循环遍历数组 for(var i=0;i<this.length;i++){ fn(this[i], i, this); } } var arr=[1, 2, 3, 4, 5]; arr.myforEach( (el,index,arr)=>{ console.log(el);//1 2 3 4 5 } );