Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Map() is broken #526

Closed
loveencounterflow opened this issue Jan 20, 2015 · 4 comments
Closed

new Map() is broken #526

loveencounterflow opened this issue Jan 20, 2015 · 4 comments

Comments

@loveencounterflow
Copy link

ES6 maps do not seem to work as described in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map; specifically, var d = new Map(); d[ [ 1, 2, ] ] = 42; will cause a key '1,2' to be created, and allows to retrieve the value with d[ '1,2' ]. Moreover, d.forEach will not iterate, d.size will always be 0, d.has(...) always returns false, and both d.keys() and d.values() will always return an empty object {}, which is wrong on more than one level.

@Fishrock123
Copy link
Contributor

@loveencounterflow Maps are not like arrays, you must use map.set(key, val) and map.get(key) to set/get values.

(This can be closed)

@Planeshifter
Copy link

To set a key, you should use the .set() method of the Map object, so you would use d.set( [ 1, 2, ]) = 42. Then everything works as expected.

@caitp
Copy link
Contributor

caitp commented Jan 20, 2015

this would be a v8 bug, not an iojs bug. That said, I don't believe this is valid.

d[ [1, 2] ] = 42 would behave like any object would, converting [1, 2] to a string (A.p.toString on arrays will be the same as array.join()), so you do get a key 1,2 with a value 42, just like you would with any object.

However, these object properties are not entries in the map, as far as the map is concerned (thus, doesn't show up in map entries/keys/values). it behaves the same (ish) as spidermonkey Map objects

@loveencounterflow
Copy link
Author

ah i see. my bad, should've read the docs!

sadly, this also means that maps are no drop-in replacements for plain old objects. i tried the examples from the MDN site, everything seems ok (when using .get() and .set()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants