Maps with object keys
Benjamin (Inglor) Gruenbaum
inglor at gmail.com
Mon Feb 17 13:09:12 PST 2014
I'm trying to work with ES6 Map objects and I ran into an interesting
problem.
I want to index/group based on several key values. Let's say my original
data is something like:
```js
[{x:3,y:5,z:3},{x:3,y:4,z:4},{x:3,y:4,z:7},{x:3,y:1,z:1},{x:3,y:5,z:4}]
```
I want to group it based on the x and y property values, so I want the
result to look something like:
```js
{x:3,y:5} ==> {x:3,y:5,z:3},{x:3,y:5,z:4}
{x:3,y:4} ==> {x:3,y:4,z:4},{x:3,y:4,z:7}
{x:3,y:1} ==> {x:3,y:1,z:1}
```
However, as the docs and draft say maps detect existence (
`Map.prototype.has ( key )`) for object the same way `===` works for
objects (specified in `SameValueZero(x, y)`).
I really don't see how to solve this other than implementing my own form of
hashing for these specific objects and 'rolling my own' logic here (instead
of working directly with `Map`s).
For comparison - in Python for example I'd use a dictionary with tuple keys.
So I'm wondering, what's the point of being able to use object keys in
`Map` objects if the equality check performed is reference equality?
I feel like I'm either missing something obvious here or we have a
usability issue on our hands.
Benjamin
(Also asked in SO
http://stackoverflow.com/questions/21838436/map-using-tuples-or-objects )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140217/190ee7c2/attachment.html>
More information about the es-discuss
mailing list