//----------extends 可以用来继承类 还可以继承原生类------------//
class VersionedArray extends Array{
constructor(){
super();
this.history=[[]];
}
commit(){
this.history.push(this.slice());
}
revert(){
this.splice(0,this.length,...this.history[this.history.length-1]);
//从0 删除到最后一个元素. 然后插入上一个版本的元素 (其实是一个数组)
}
}
let x=new VersionedArray();
x.push(1);
x.push(2);
console.log(x);
console.log(x.history);
x.commit();
console.log(x.history);
x.push(3);
console.log(x);
console.log(x.history);
x.revert();
console.log(x);
console.log(x.history);
console