class limitArray extends Array{ constructor(maxNum){ super() Object.defineProperty(this,"maxNum",{ enumerable:false,//是否可以被枚举 value:maxNum, writable:true }); } push(item){ Array.prototype.unshift.call(this,item) if(this.length>this.maxNum){ Array.prototype.pop.call(this) } } } module.exports=limitArray;