When I am trying to call a static method from constructor in javascript it says the method doesn't exist.
class TestClass {
constructor(){
this.staticMethod();
}
static staticMethod() {
}
}
This works fine if i try to call a normal method from constructor. If static methods belongs to class instead of instance why it's not allowing them to call from constructor?
this.constructor.staticMethod()
can be used to avoid referring to the class directly (particularly useful for class inheritance and pasted code).
You have to call it like this:
TestClass.staticMethod()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With