day1:js数组方法push重写

55 阅读1分钟

day1:js数组方法push重写

Array.prototype._push = function (...arg) {
    const params = [...arg];
    for (let i = 0, len = params.length; i < len; i++) {
        this[this.length] = params[i];
    }
    return this.length;
}

const arr1 = [12];

console.log(arr1._push(11, 1))
console.log(arr1)