//1: 模拟实现 forEach方法
Array.prototype.arr_forEach = function (callback,thisArg) {
var _this = this;
if(arguments.length > 1){
_this = thisArg
}
if (!Array.isArray(this)) {
throw new Error('param1 must be an Array||String')
}
if (typeof callback !== 'function' && typeof callback !== 'Function') {
throw new Error('param2 must be an function')
}
for (let i = 0; i < _this.length; i++) {
callback.call(_this,_this[i], i, _this);
}
};
var arr = [1,213,123,2,2,1,1];
var arr1 = [1,2,10,111];
arr.arr_forEach(function(item,index,arr){
console.log(item);
})
欢迎修改指正!