SOURCE

// map

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

const arr = [1,2,3,4,5]
let newArr = arr.map(item => {
    return item + 1
})
console.log(newArr)
let newArr2 = arr.myMap(item => {
    return item + 1
})
console.log(newArr2)
console 命令行工具 X clear

                    
>
console