Subclassing ES6 objects with ES5 syntax.
Kevin Smith
zenparsing at gmail.com
Sat Apr 25 22:58:26 UTC 2015
>
> I think I'd rather see `Promise.resolve` changed to use `this.constructor`
> instead of `this.[[PromiseConstructor]]`, like every other Promise-related
> method. Can someone who feels strongly otherwise give me the use case for
> `[[PromiseConstructor]]` existing?
>
I'll give it a shot.
"Promise.resolve", executed on a constructor C, with argument x, should
only return x if x was created by C.[[Construct]]. Otherwise it should
create an instance of C which is resolved with x.
If we used "x.constructor" to determine the actual constructor, then
someone could just change the "constructor" property for x and fool someone
who wrote "C.resolve(x)" and expected to get an instance of C back.
It would be an unreliable, unsound conversion function.
Proper subclassing requires subclassing support from the engine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150425/ad58da8c/attachment.html>
More information about the es-discuss
mailing list