array like objects

Brendan Eich brendan at mozilla.com
Tue Dec 15 07:21:11 PST 2009


On Dec 15, 2009, at 5:05 AM, Jorge Chamorro wrote:

> On 15/12/2009, at 13:51, P T Withington wrote:
>> (...)
>> I once had the vain hope that I could say:
>>
>> function MyArray () {}
>> MyArray.prototype = [];
>>
>> to create my own subclasses of Array.  That might have lessened the  
>> need for isArrayLike.
>
> For that, we'd need an Array.create(). It might be a good thing... ¿?

What would Array.create do?

Tucker is looking for a way to compose custom [[Put]] with prototype- 
based delegation. My reply suggested that if [[Put]] were a property  
name, just like "length", and looked up along the prototype chain, so  
that the default [[Put]] was in Object.prototype, the custom Array  
[[Put]] that updates .length to be one greater than the highest index  
were on Array.prototype (or on [] in Tucker's example, but in general  
on the class prototype would suffice), etc., then we would not need  
anything new like Array.create.

We would have one mechanism, prototype-based delegation, for finding  
methods (internal or external), and a complementary private-name  
scheme for generating and (implicitly, in the case of certain private  
names built into the language) using names that can't be expressed  
outside of an abstraction or module boundary.

That still seems winning to me, but I didn't implement anything like  
it in 1995. It may have come up in ES1 days (I have vague memories),  
but no one implemented it so it was a dark horse for standardization.

/be


More information about the es-discuss mailing list