Answer the question
In order to leave comments, you need to log in
Why do I get undefined when accessing the parent property?
Parent:
class a {
protected _selected: any;
get selected() {
return this._selected;
}
set selected(value: any) {
this._selected = value;
}
}
class b extends a {
set selected(value: any) {
super.selected = value;
}
get selected() {
return super.selected;
}
}
let _b = new b();
_b.selected = "333";
console.log(_b.selected); // 333
get selected() {
return this._selected;
}
console.log(_b.selected);
Answer the question
In order to leave comments, you need to log in
In the original, the child was without a getter, the value of the child overlapped the value of the parent, this is how prototypal inheritance works.
In your version, everything works, since selected is declared with both a getter and a setter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question