Design principles for extending ES object abstractions

Allen Wirfs-Brock allen at
Fri Jul 8 18:29:34 PDT 2011

On Jul 8, 2011, at 5:53 PM, David Herman wrote:

> I think I still haven't fully grokked what <| means on array literals, but could it also be used to "subclass" Array? For example:

yes, it creates a new object that is an array instance ([[Class]]=='Array', support the length constraints, etc.) that has LHS of <| as its [[Prototype]] value.
(BTW, in my initial working draft for the "ES6" spec. I have already purged [[Class]] from the specification)

>     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.

All of them.  They are all generic.  However, subarray instances have all the internal state and methods that make them true arrays so even if some of the inherited Array methods weren't generic they would still work.


More information about the es-discuss mailing list