Why is this.fullName
appearing empty in the show()
method?
class Person {
protected name: string = "";
constructor(name: string) {
this.makeSir(name);
}
makeSir(name: string) {
this.name = "sir" + name;
}
}
class Man extends Person {
protected fullName = "";
constructor(name: string) {
super(name);
}
makeSir(name: string) {
super.makeSir(name);
this.fullName = "***" + name;
console.log(this.fullName);//[LOG]: "***john"
}
show() {
console.log(this.fullName);//[LOG]: ""
}
}
const man = new Man("john");
man.show();
What steps can be taken to resolve this issue?