this

91 阅读1分钟

let arr1={ length:0, push(val){ this[this.length]=val this.length++ }, forEach(fn){ for (let i = 0; i < this.length; i++) { fn(this[i],i)

            }
        },
        push(val){
            Array.prototype.push.call(this,val)
        },
        forEach(fn){
            Array.prototype.push.call(this,fn)
        }
    }
    arr1.push('aaa')
    arr1.push('bbb')
    arr1.forEach(r=>{
        console.log(r);
        
    })