I cannot find any information about how one defines static data members in JavaScript using the (relatively new) class syntax. Is it even possible? Please see the following example code:
class Foo {
constructor() {
this.name = 'Default Name for each Instance';
// staticData1 = 'Static Data 1'; // syntax error
let staticData2 = 'Static Data 2'; // undefined outside
}
doSthSpecial() {
console.log('Executing a method from instance "' + this.name + '"');
}
static doSthStatic() {
console.log('Executing a method that does the same for each instance of "Foo"');
}
}
foo = new Foo();
console.log(foo.name);
foo.doSthSpecial();
Foo.doSthStatic();
// The problematic case:
console.log(Foo.staticData2);