3 ms·
> Properties Overriding Accessors (and vice versa) is an Error Not sure I like this. Can definitely imagine the following being a realistic scenario, and see
by seph-reed 6y ago
> Properties Overriding Accessors (and vice versa) is an Error
Not sure I like this. Can definitely imagine the following being a realistic scenario, and see no reason to disallow it:
class Base {
public num = 42;
}
class Child extends Base {
protected _num = 42;
// no longer allowed in 4.0
public get num() { return this._num; }
public set num(newVal) {
alert(`new num ${newVal}`);
this._num = newVal
}
}
Did I misunderstand something?
- idbehold 6y agoI think this error only happen if you don't provide both a getter and setter in the case where the class you're extending uses an instance property. Or if your extended class uses an instance property where the class it is extending only provided a getter.
- seph-reed 6y agoAh. Okay. That would be fair.