extending an ES6 class using ES5 syntax?

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon May 16 21:02:08 UTC 2016


Good call, however, it wouldn't work so well with constructor because
`Object.setPrototypeOf(B, A)` is still neede here, and also trashing
initial `B.prototype` with an all enumerable assignment still wouldn't
solve this case.

```js
B.prototype = {
  __proto__: A.prototype,
  constructor: B, // now enumerable
  method() {
    // also enumerable
  }
};
```

Maybe having a special case for "classes", the only place where prototype
is usually modified, would solve them all?



On Mon, May 16, 2016 at 8:20 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>
wrote:

>
> > On May 16, 2016, at 10:31 AM, Jason Orendorff <jason.orendorff at gmail.com>
> wrote:
> >
> > ...
> > `B.prototype = Object.create(A.prototype)` is less of a problem, for
> > our implementation, because objects created by constructor B later get
> > a prototype chain where every object is clean (none of them have ever
> > had their [[Prototype]] changed; so no assumptions have been
> > invalidated).
> >
>
> Jason,
>
> Do you or have you considered special casing __proto__ used in object
> literals:
>
> ```js
>
> let p = {
>    __proto__: Array.prototype,
>    m1 () {…},
>    m2 () {…}
> };
> ```
>
> Lots of good declarative shape information in that form.
>
> Allen
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160516/c26a1915/attachment.html>


More information about the es-discuss mailing list