How can I create static variables in Javascript?
If you are using the new class syntax then you can now do the following:
class MyClass {
static get myStaticVariable() {
return "some static variable";
}
}
console.log(MyClass.myStaticVariable);
aMyClass = new MyClass();
console.log(aMyClass.myStaticVariable, "is undefined");
This effectively creates a static variable in JavaScript.