相当于javascript中类声明的原型

时间:2018-10-02 05:43:03

标签: javascript oop object prototype prototypal-inheritance

我已经阅读了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

0 个答案:

没有答案