I have a super class Foo with a static method and an instance method which both console.log() a static property.
How can I get the static method to property reference the correct static property. As you can see here it is only referencing the super class property and not the sub class property.
class Foo{
whoAmI(){
console.log(this.constructor.someStaticVar)
}
static whoAmI_static(){
console.log(Foo.someStaticVar) // is there a way to call the calling class and not the superclass here?
}
}
Foo.someStaticVar = 'I am Foo'
class Bar extends Foo{
}
Bar.someStaticVar = 'I am Bar'
let barInstance = new Bar()
Bar.whoAmI_static()
barInstance.whoAmI()
Expected output:
I am Bar
I am Bar
Actual Output:
I am Foo
I am Bar