bruant at enseirb-matmeca.fr
Fri Mar 18 10:21:59 PDT 2011
Le 18/03/2011 18:02, John-David Dalton a écrit :
> Date.create, Function.create and the like clutters the API. I would be
> for a more generic Object.setPrototypeOf() addition.
The problem is that it would break an invariant of the ECMAScript
language which is that the prototype of an object is set at
initialization time (from script with Object.create (and soon
Proxy.create), but also in internal methods) and is immutable afterward.
>> I think you can also achieve what you want with Harmony proxies, so
>> you'll have that option in the next edition of ES.
> , ind
> I don't know. It would need to preserve internal [[Class]] as __proto__.
Proxies don't allow to set the class, indeed. Moreover, they are not
optimized as arrays can be.
That's the reason why Array.create and the like are a good compromise.
They allow to set the prototype at object initialization and are of the
right [[Class]] internally (with optimizations if there are some). But
they do not break the prototype immutability invariant.
I do not think that a more generic solution is possible with all these
I'm glad to read that coming to an agreement on the topic is on the
agenda of the next TC-39 meeting and am looking forward to see the result.
More information about the es-discuss