Separating a Hash type from Object

Brendan Eich brendan at mozilla.org
Tue May 1 21:50:02 PDT 2007


On May 1, 2007, at 9:41 PM, Andrew Dupont wrote:

> Brendan Eich wrote:
>> How about a magic namespace:
>>
>> foo.direct::["toString"]
>>
>> or some such? Then 'use namespace direct' would result in
>> foo.toString() or an implicit conversion failing if there were a
>> foo.direct::["toString"]. So a magic namespace may be the wrong UI.
>> How about special syntax?
>>
>> foo#.toString
>> foo#["toString"]
>>
>> and of course
>>
>> let dict = #{a:1, b:2, c:3};
>>
>> ?
>>
>> /be
> I like it. Let me think out loud...
>
> var foo = {};
> foo.toString; //-> function() {}
> foo#.toString; //-> undefined

So far so good.

> foo.toString = "bar";

This must create a direct property in the object referenced by foo,  
which shadows Object.prototype.toString. So:

> foo + "" //-> Error

agreed...

> foo#.["toString"]; //-> undefined

This isn't right, given the shadowing rule of JS/ES.

> foo#.toString = "bar";
> foo#.toString; //-> "bar";
> delete foo.toString; //-> true
> foo#.toString; //-> "bar";

I'm confused -- do you intend that foo#.toString name a property in  
no namespace with identifier 'toString' in some object, or a property  
in a hidden namespace with local name 'toString'?

> delete foo#.toString;
> foo#.toString; //-> undefined

This seems consistent no matter what.

> If I'm correct in all these assumptions, then this seems like a good
> solution. I also like PT's "for..in own" syntax for discovering which
> keys are defined this way.

That thought has occurred, but it doesn't match the |in| operator. A  
custom iterator factory might be better; there are lots of ways to  
iterate.

/be




More information about the Es4-discuss mailing list