Design principles for extending ES object abstractions

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Jul 8 17:48:22 PDT 2011


On Jul 8, 2011, at 5:16 PM, Brendan Eich wrote:

> On Jul 8, 2011, at 3:49 PM, Allen Wirfs-Brock wrote:
> 
>> 2) Anything that can be done declaratively can also be done imperatively.
> 
> What's the imperative API for <| (which has the syntactic property that it operators on newborns on the right, and cannot mutate the [[Prototype]] of an object that was already created and perhaps used with its original [[Prototype]] chain)?

Fair point and one I was already thinking about :-)

For regular objects, it is Object.create.

For special built-in object with literal forms, I've previously argument that  <| can be used to implement an imperative API:

Array.create = function (proto,members) {
    let obj = proto <| {};
    Object.defineProperties(obj,members);
     return obj;
}

Basically, <| is sorta half imperative operator, half declaration component.

This may be good enough.  It would be nice it it was and we didn't have to have additional procedural APIs for constructing instances of the built-ins.  Somebody has already pointed out <| won't work for built-in Date objects because they lack a literal form. I think the best solution for that is to actually reify access to a Date object's timevalue by making it a private named property.   BTW, way did ES1(?) worry about allowing for alternative internal timevalue representations?  If in really there really any perf issues that involve whether or not the timevalue is represented as a double or something else?

Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110708/587d324d/attachment.html>


More information about the es-discuss mailing list