Is __proto__ ready needed?
Maybe some new API, like createPrototypeModified(obj, newPrototype)
, it copies all eigen-properties of obj
to a new object with its prototype is newPrototype
.
I think that once an object is created, its prototype should be constant.
While many people would fully agree with you, standardizing __proto__
isn't
about whether it is needed, but about it being out in the wild and TC39's
desire to let the EcmaScript standard reflect reality. Which, you know,
kinda makes sense: once a genie is out of its bottle, you aren't doing
yourself a favor by pretending it to still be safely contained.
Also note that there have been lots of discussions on this very topic in the past, which you might want to skim through to get an overview of all the arguments: www.google.com/search?q=site%3Amail.mozilla.org%2Fpipermail%2Fes-discuss
On Mon, Jun 10, 2013 at 5:06 AM, BelleveInvis <infinte.cdda at hotmail.com>wrote:
I think that once an object is created, its prototype should be constant.
And we should add features to implement sub-typing built-in types, like Array, since this code exists (found in Zepto):
Classes offer exactly that:
class Zepto extends Array {}
Object.setPrototypeOf
is really needed.
Use cases for that are as rare as for eval
, but exist and are valid.
Currently I work on database engine written in JavaScript, and rely quite
heavily on __proto__
.
Once I was asked By David Herman to explain my use cases. I prepared
following gist then: gist.github.com/medikoo/5602644
On Mon, Jun 10, 2013 at 10:50 AM, medikoo <medikoo+mozilla.org at medikoo.com>wrote:
Object.setPrototypeOf is really needed.
From the meeting notes:
Conclusion: proto is an accessor on Object.prototype. The setter mutates [[Prototype]]. There is no “poison pill”. We will provide both Object.setPrototypeOf and std:reflect setPrototypeOf.
yep, that's awesome ... too bad not a single engine exposed yet such easy change ever for both V8 and/or SpiderMonkey since everything is already in place, only the public method exposed to JS is missing (and for V8 I've already porposed a patch to drop the poison pill but nothing happened ...)
I just hope V8 will do this change before node.js will be out in its "final" 1.0 version and looking forward to see FF nightly and mobile adopting that too.
br
I think that once an object is created, its prototype should be constant.
And we should add features to implement sub-typing built-in types, like Array, since this code exists (found in Zepto):
zepto.Z = function(dom, selector) { dom = dom || [] dom.__proto__ = $.fn dom.selector = selector || '' return dom }
Using proxies may be one way, but it should be more convinent.