23

コンストラクターで x と y がどのように宣言されているかを確認してください。

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
  toString() {
    return '(' + this.x + ', ' + this.y + ')';
  }
}

たとえば、関数の外部でプロパティを宣言する方法はありますか:

class Point {
  // Declare static class property here
  // a: 22
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
  toString() {
    return '(' + this.x + ', ' + this.y + ')';
  }
}

だから私は22にaを割り当てたいのですが、コンストラクタの外でもクラス内でできるかどうかはわかりません..

4

2 に答える 2