我已经阅读了Douglas Crockford的Javascript the good parts
,并试图了解最近在javascript中引入的类声明。看一下这段代码:
class Rectangle extends Shape {
constructor(height, width) {
super(4);
this.height = height;
this.width = width;
}
get width() {
console.log('getter')
return this.width();
}
set width(w) {
console.log('setter')
this.width = w;
}
calcArea() {
return this.height * this.width;
}
static numSides() {
return 4;
}
superCall() {
return super.func();
}
}
这将如何转换为原型模式,该模式应该是JavaScript的true nature
?