Separating a Hash type from Object

Brendan Eich brendan at mozilla.org
Tue May 1 18:36:44 PDT 2007


On Apr 30, 2007, at 2:43 PM, Andrew Dupont wrote:

> However, it doesn't fix the lack of key safety.
>
> var foo = {};
> foo + ""; //-> "[object Object]"
>
> foo.toString = "bar";
> foo + ""; //-> Error: Can't convert foo to primitive type
>
> This bothers me.  The original "toString" property can still be
> accessed with an intrinsic:call, but that doesn't help with the
> automatic string coercion in the example above.

use namespace intrinsic;

does help there.

> I think this has been discussed before on this ML, but nobody has
> come up with an easy answer here.  Ideally, speaking from a narrow
> perspective, I'd like to be able to distinguish dot notation from
> bracket notation...
>
> foo["toString"]; //-> "bar";
> foo.toString;     //-> function() {}
>
> ... but I fear that's too large a can of worms to open.

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




More information about the Es4-discuss mailing list