对象借用数组的方法
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);
});
打印效果如下
