this理解

121 阅读1分钟

用push在对象里加数据

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