Here is a snippet of code that I'm working on. In my child class, I need to use an arrow function called hello()
.
When I try calling the.greeting()
in the parent class constructor, I encounter an error:
index.ts:29 Uncaught TypeError: this.hello is not a function at Child.greeting ...
The strange thing is that the error disappears when I switch from using a regular function to an arrow function.
I am puzzled by this issue and would appreciate any insights or solutions you may have.
abstract class Parent{
constructor(){
this.greeting();
}
abstract hello();
greeting(){
this.hello();
}
}
class Child extends Parent{
hello = ()=>{
console.log('hello there');
}
}
const child = new Child();