Jason Orendorff (2014-02-18T02:50:44.000Z)
On Mon, Feb 17, 2014 at 3:09 PM, Benjamin (Inglor) Gruenbaum
<inglor at gmail.com> wrote:
> I'm trying to work with ES6 Map objects and I ran into an interesting
> problem.

Yes! Well done.

We've noticed this too, and considered (a) allowing objects to provide
their own hash and equals operations, as in Java and Python; (b)
allowing the Map user to specify hash and equals operations for the
Map at construction time. These were rejected partly because both
ideas would make Map behavior observably nondeterministic, or else
overspecify. Also because object hash codes would be exposed to users,
and ensuring that those do not leak any information about object
addresses would likely make them slow.

The solution that prevailed is (c) introduce value types in ES7. With
value types, you'll be able to declare an aggregate value type, much
like a Python namedtuple, to use as your Map key. Values of that type
can be compared for equality with ===, like Python tuples, and Map
will work accordingly.

Until value types are spec'd and implemented, the other workarounds
already mentioned in this thread will have to do, I'm afraid.

-j
domenic at domenicdenicola.com (2014-02-21T16:24:47.988Z)
On Mon, Feb 17, 2014 at 3:09 PM, Benjamin (Inglor) Gruenbaum <inglor at gmail.com> wrote:
> I'm trying to work with ES6 Map objects and I ran into an interesting
> problem.

Yes! Well done.

We've noticed this too, and considered (a) allowing objects to provide
their own hash and equals operations, as in Java and Python; (b)
allowing the Map user to specify hash and equals operations for the
Map at construction time. These were rejected partly because both
ideas would make Map behavior observably nondeterministic, or else
overspecify. Also because object hash codes would be exposed to users,
and ensuring that those do not leak any information about object
addresses would likely make them slow.

The solution that prevailed is (c) introduce value types in ES7. With
value types, you'll be able to declare an aggregate value type, much
like a Python namedtuple, to use as your Map key. Values of that type
can be compared for equality with ===, like Python tuples, and Map
will work accordingly.

Until value types are spec'd and implemented, the other workarounds
already mentioned in this thread will have to do, I'm afraid.