Assignment to a super properly definitely has its uses, in the same way
that calling a super method does, though definitely less common. Consider
an example where a subclass wants to override a parent class's accessor
property:

```
class Parent {
  get prop(){
    return this._prop;
  }
  set prop(val){
    this._prop = val;
  }
}

class Child extends Parent {
  get prop(){
    return super.prop.slice('prefix'.length);
  }
  set prop(val){
    super.prop = 'prefix' + val;
  }
}

```

Unless the child class wants to (and is able to) duplicate the parent
classes logic, or manually trigger the parent getter and setter functions,
assigning to the super accessor is the only approach.

On Fri, Feb 19, 2016 at 7:20 PM, ziyunfei <[email protected]> wrote:

> Today I saw a V8 test case [1] which took me a long time to figure out why
> it runs like this:
>
> class Test {
>   m() {
>     super.length = 10;    // `super.length' here has the same effect as
> `this.length'
>     console.log(super.length);    // but `super.length' here is
> `Test.prototype.__proto__.length' (i.e. `Object.prototype.length') which
> still remains `undefined'
>   }
> }
> var array = [];
> Test.prototype.m.call(array);
> assertEquals(10, array.length);
>
> This syntax is so confusing and I couldn't think of any real use case for
> it, so should we make `SuperProperty = AssignmentExpression' an early error?
>
> Also, I found an old es-bug thread [2] discussed about this.
>
> [1]
> https://chromium.googlesource.com/v8/v8/+/77e30f013a221527bb4ab955188aec44f10fee7f/test/mjsunit/es6/classes-super.js
>
> [2] https://bugs.ecmascript.org/show_bug.cgi?id=3246
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to