On Fri, Apr 24, 2015 at 10:46 AM, Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:

> So you should do the same with Promise methods but then you'll see overall
> a quite consistent performance drop when using all these subclasses.
>

Well, not exactly.  The Promise methods are all written to use the correct
constructor (perhaps a (welcome) artifact of the fact that they were
spec'ed before this change in instantiation mechanism?):
```
$ iojs
> var P2 = function P2(x) { var self = new Promise(x);
Object.setPrototypeOf(self, P2.prototype); return self; }
undefined
> Object.setPrototypeOf(P2, Promise);
[Function: P2]
>   P2.prototype = Object.create(Promise.prototype);
{}
>   P2.prototype.constructor = P2;
{}
> p = P2.resolve(5);
{}
> p instanceof Promise
true
> p instanceof P2
true
> p2 = p.then(function(){return 6; });
{}
> p2 instanceof P2
true
```
It's true that the `Object.setPrototypeOf` inside the constructor is quite
unfortunate for performance.  :( But at least you don't have to repeat that
inside each instance method.

Does anyone have a better idea for creating an ES6-compatible subclass
using ES5 syntax, without resorting to `Object.setPrototypeOf` when every
instance is constructed?
  --scott
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to