I need to change a Parent's static method from a subclass.
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static I read:
Static method calls are made directly on the class and are not callable on instances of the class.
In the example below, I have a Parent
class with a foo()
method which calls the bar()
method (both static). I would need to change bar
from Child
subclass so that calling Child.foo()
will call the modified bar method and not the original one.
Is there a possibility (maybe something in the Child's constructor
)?
class Parent {
static foo() {
Parent.bar();
}
static bar() {
console.log("HERE I AM");
}
}
class Child extends Parent {
static bar() {
super.bar(); // maybe not what I want?
console.log(", FELLAS!");
}
}
Parent.foo(); // HERE I AM
Child.foo(); // HERE I AM, FELLAS! (need this!)