myForEach

Array.prototype.myForEach = function (callback, thisArg = undefined) {
    if (typeof callback !== 'function') {
        throw new TypeError(`${callback} is not a function`);
    }
    let index = 0
    const len = this.length
    while (index < len) {
        if (index in this) callback.call(thisArg, this[index], index, this)
        index++
    }
}

  

posted @ 2023-02-17 00:58  671_MrSix  阅读(7)  评论(0编辑  收藏  举报