class

2018-04-02  本文已影响0人  Haiya_32ef
class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  toString() {
    return '(' + this.x + ', ' + this.y + ')';
  }
}
class Rectangle {
 constructor(length, width) {
   console.log(new.target === Rectangle);
   // ...
 }
}

class Square extends Rectangle {
 constructor(length) {
   super(length, length);
 }
}

var obj = new Square(3); // 输出 false
class A {
  constructor() {
    this.x = 1;
  }
}

class B extends A {
  constructor() {
    super();
    this.x = 2;
    super.x = 3;
    console.log(super.x); // undefined
    console.log(this.x); // 3
  }
}

let b = new B();
上一篇 下一篇

猜你喜欢

热点阅读