2 回答
TA贡献1995条经验 获得超2个赞
使用ES5 构造函数仿写上面的答案
function List1(){
this.items = [];
for(var i =0; i<arguments.length;i++){
this.items.push(arguments[i]);
}
this.length = arguments.length;
this.add = function(){
for(var i =0; i<arguments.length;i++){
this.items.push(arguments[i]);
}
this.length = this.items.length;
}
}
TA贡献1966条经验 获得超4个赞
class List{
constructor(...items){
this.items = items
this.length = items.length
}
add(...items) {
this.items.push(...items)
this.length = items.length
}
}
添加回答
举报