I am trying to override one method from the parent class, but there are some issues.
Below is the code snippet of my scenario which I am trying.
class Parent {
add = () => {
console.log('Parent method');
}
}
class Child extends Parent {
add () {
console.log('Child Method');
}
}
// Creating an instance
const child = new Child();
child.add();
It is calling the Parent method add as that is arrow function, Can someone explain why this is happening. If I make the parent function a simple javascript method then child is able to override.
Additonal Details :
- I don't have access to Parent as it is part of library.
- I can't make my child class method as instance properties (arrow function) , the reason for being that there are further specification written for child (child of child) and If we use arrow functions we will not be able to call the super.
- Child function name can't be renamed.