I'm having a pretty strange problem:
class AddOrSelectAddress {
static allCountries = {
AD: "Andorra",
AE: "Vereinigte Arabische Emirate",
AF: "Afghanistan",
// ...
};
constructor() {
console.log('new');
console.log(this.allCountries); // prints "undefined"
}
}
const myInstance = new AddOrSelectAddress();
Why does that happen? I would expect, that the this.allCountries would contain the object there.
thiskeyword from non-static methods. You need to call them using the class name:CLASSNAME.STATIC_METHOD_NAME()or by calling the method as a property of the constructor:this.constructor.STATIC_METHOD_NAME()." (Source) - It's for methods but I would guess that this will also count for properties.