Answer the question
In order to leave comments, you need to log in
Why is the property of the inherited class undefined inside the implementation of the abstract method?
There is a code. Why does this point to the class in which it is called, and this.name to the parent class? How to fix?
abstract class Abstract {
protected name: string;
constructor () {
this.abstractMethod();
}
protected abstract abstractMethod (): void;
}
class Concrete extends Abstract {
protected name: string = 'Concrete';
protected abstractMethod () {
console.log(this, this.name); // Concrete, undefined
}
}
new Concrete();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question