Adding a non-class-syntax method for subclassing native objects

Renki Ivanko fatalis.erratum at gmail.com
Thu May 5 14:58:41 UTC 2016


Thanks, I had missed the `Reflect.construct()` method. One problem with
your solution is that the `Array` iterator methods like `.map()` use
`this.constructor[Symbol.species]` to construct their result, so the
prototype actually needs to be set like this:

```
SubArray.prototype = Object.create(Array.prototype, {
  constructor: {
    value: SubArray,
    writeable: true,
    enumerable: false,
    configurable: false,
  }
})
```

Setting the `constructor` property on the prototype is part of the
MakeConstructor operation (for full parity the `prototype` property should
be defined as non-enumerable, non-configurable as well).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160505/8f37fdf1/attachment.html>


More information about the es-discuss mailing list