Deklarieren Sie eine Klasseneigenschaft außerhalb einer Klassenmethode
Siehe, wie x und y im Konstruktor deklariert sind:
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
gibt es eine Möglichkeit, Eigenschaften außerhalb von Funktionen zu deklarieren, zum Beispiel:
class Point {
// Declare static class property here
// a: 22
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
So möchte ich ein bis 22 zuweisen, aber ich bin nicht sicher, ob ich es außerhalb des Konstruktors aber noch innerhalb der Klasse tun kann ..