I think I still haven't fully grokked what <| means on array literals, but
could it also be used to "subclass" Array? For example:
function SubArray() {
return SubArray.prototype <| [];
}
SubArray.prototype = new Array;
I'm not sure what Array.prototype methods would or wouldn't work on instances
of SubArray.
Dave
On Jul 8, 2011, at 5:48 PM, Allen Wirfs-Brock wrote:
>
> 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
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss