SOURCE

//forEach()
// 跟map类似,不过没有返回值
let arr = [1,2,3,4,5]

Array.prototype.myForEach = function(callback,thisArg) {
    if(this == null) {
        throw new TypeError('this callback is null or undefined')
    }
    if(typeof callback !== 'function') {
        throw new TypeError(callback + 'is not function')
    }
    const O = Object(this)
    const len = O.length >>> 0
    for(let i=0;i<len;i++) {
        if(i in O) {
            callback.call(thisArg,O[i],i,O)
        }
    }
}

arr.myForEach(item => {
    console.log(item)
})
console 命令行工具 X clear

                    
>
console