Override a setter, and the getter must also be overridden

后端 未结 1 1229
我寻月下人不归
我寻月下人不归 2020-11-28 15:40
class AbstractClass {

    constructor() {
    }

    set property(value) {
        this.property_ = value;
    }

    get property() {
        return this.property_         


        
1条回答
  •  独厮守ぢ
    2020-11-28 16:29

    Yes, this is intentional (a part of the spec). If an object has an own property (.property in your example), this property will be used and not an inherited one. If that property is existent, but is an accessor property without a getter, then undefined will be returned.

    Notice that this behaviour has not changed from ES5.

    0 讨论(0)
提交回复
热议问题