I’m, writing the below code, I can’t understand how it is working. In C# or Java when we use base or super keyword it returns values but in typescript, I’m getting "undefined". If I use "this" instead of "super" it is working.
class Person {
public firstName: string;
public lastName: string;
constructor(fn: string, ln: string) {
this.firstName = fn;
this.lastName = ln;
}
}
class Customer extends Person {
constructor(fn: string, ln: string) {
super(fn, ln);
}
displayDetails() {
console.log(`First Name :${super.firstName}tLast Name :${super.lastName}`);
}
}
let c = new Customer("Pradeep", "Kumar");
c.displayDetails();
could someone explain the execution?
2
Answers
Don’t use
super
butthis
Playground
See relevant docs at MDN: super