Struggling a bit with inheritance of static properties. My Main class has a static property a
. I would like for my Sub class to override that property. Also, I can only access 'a' in the constructor using Main.a
. I would like that new Sub()
uses Sub.a
in its constructor. Can I do this, if so, how?
class Main {
static a = "Is Main";
constructor() {
console.log( "Constructor Main " + Main.a) // "Is Main"
console.log( "Constructor This " + this.a) // undefined
}
}
class Sub extends Main {
static a = "Is Sub"
}
var sub = new Sub();
console.log( sub.a ); // undefined
/*
Constructor Main Is Main
Constructor This undefined
undefined
*/