Object ID's
P T Withington
ptw at pobox.com
Tue Mar 20 18:34:27 PDT 2007
On 2007-03-20, at 21:09 EDT, Lars T Hansen wrote:
>>
>> It *feels* more critical than the lambda syntax that is getting so
>> much attention in the other current thread.
>
> Amen to that, though there are several kinds of dictionary types one
> could discuss, from the simple property-less object type (more
> primitive than Object) to elaborate dictionary classes.
The last time this came up, I said:
> On 2007-01-05, at 20:14 EST, Brendan Eich wrote:
>> Another item falling out of the ES4 spec: hashes mapping string to
>> value where the mapping is not polluted by Object.prototype. A
>> late "save" may be possible, if anyone can suggest syntax. E.g.,
>> var hash = #{'foo':1, 'bar':2, 'baz':3}; alert('toString' in hash)
>> => false. Eek, yet another attempt to use #.
>
> Since you can't build a pure hash in Javascript, this would be a
> _highly_ desirable addition. Naive use of Object for hash has been
> the source of a number of subtle bugs in our code. One might even
> be so bold as to make Hash the primitive and Object inherit from it?
>
> We would have many uses for Hash in our code base. I have defined
> a dictionary class that I use for some cases, but often have had to
> trade correctness for performance.
>
> A literal syntax would not be that important if you could have a
> constructor with named arguments. (Because the constructor's
> `arguments` property would be a Hash?) It would also be useful to
> have a constructor that constructed a new hash from an existing one.
>
>> (Should these map value to value, rather than string to value?
>> E4X (ECMA 357) already introduced QName objects as identifiers, so
>> one can't pretend all properties are named by strings, if one
>> believes in E4X.)
>
> value -> value would be a bonus that I would greatly appreciate,
> but then won't you need to define a protocol for extending hash-
> code computation and `===`?
I think having a pollution-free dictionary type would be much more
important that the `=>` syntax shortcut. Having a dictionary that
can map values to values would be a bonus, but also important. You
can't do either of these things efficiently in the language, which is
a good reason to make them built in.
More information about the Es4-discuss
mailing list