Maps with object keys

Jason Orendorff jason.orendorff at
Mon Feb 17 18:50:44 PST 2014

On Mon, Feb 17, 2014 at 3:09 PM, Benjamin (Inglor) Gruenbaum
<inglor at> 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.


More information about the es-discuss mailing list