Answer the question
In order to leave comments, you need to log in
Late static binding, how to use overridden property in parent class?
I'm making a library, I need something like late static linking, I don't quite understand how to do it in ts.
There is a class, it has static fields/methods, it will be inherited, and its methods should work with static properties/heir methods, how?
typescript
class A {
static text: string = 'A class';
static getA() {
return A.text; // что-то типа static.text
}
}
class B extends A {
static text: string = 'B class';
}
console.log(B.getA()); // A class, нужно B class
Answer the question
In order to leave comments, you need to log in
It's incredibly difficult, but still possible.
class A {
static text: string = 'A class';
static getA() {
return this.text; // что-то типа static.text
}
}
class B extends A {
static text: string = 'B class';
}
console.log(A.getA()); // A class
console.log(B.getA()); // B class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question