87,993
社区成员
发帖
与我相关
我的任务
分享
function MyArray() {
Array.apply(this, arguments);
}
MyArray.prototype = Object.create(Array.prototype, {
constructor: {
value: MyArray,
writable: true,
configurable: true,
enumerable: true
}
});
var colors = new MyArray();
colors[0] = "red";
console.log(colors.length); // 0
colors.length = 0;
console.log(colors[0]); // "red"
class MyArray extends Array {
// 空代码
}
var colors = new MyArray();
colorsp[0] = 'red';
console.log(colors.length); // 1
colors.length = 0;
console.log(colors[0]); // undefined