Earlier quoted context omitted.
It's probably to get around the non-deterministic ordering of objects. New Map({'a': 'bar', '1': 'foo'}); Would flip the order of the keys.
To be pedantic, in all modern browsers the order is deterministic. But it certainly can be surprising. For those who aren't aware, browser Javascript maintains insertion order, except for numeric keys, which are in numeric order ahead of all other keys.
ES6 Maps are now on by default in Chrome 38
51–54 of 54 posts
Re: ES6 Maps are now on by default in Chrome 38
#52Earlier quoted context omitted.
Still, I'd like if Map worked with values m = new Map([[new String(1), 1]]) > Map { "1": 1 } m.get("1") > undefined
I'm not sure what you'd want here, you specifically allocated a string object and since JS has no notion of object equality it can only use identity.
The fact that, up to ES5, there's been no agreement on which name to use for the equality function and no default implementation for it it's of no excuse to avoid the issue. It's their (the people who standardized it) Map type, and they should've been able to make it as useful as possible.
Re: ES6 Maps are now on by default in Chrome 38
#53Earlier quoted context omitted.
I'm not sure what you'd want here, you specifically allocated a string object and since JS has no notion of object equality it can only use identity.
You can still iterate through all the properties of an object (the indexes associated to the code units, in case of a String) and recursively implement equality on them this way. The fact that, up to ES5, there's been no agreement on which name to use for the equality function and no default implementation for it it's of no excuse to avoid the issue. It's their (the people who standardized it) Map type, and they shou…
Can't do that for a hashmap since the value can change (by mutating the object) the hash would have to change as well and the object would have to move around. Not a sane proposition.
Re: ES6 Maps are now on by default in Chrome 38
#54Earlier quoted context omitted.
You can still iterate through all the properties of an object (the indexes associated to the code units, in case of a String) and recursively implement equality on them this way. The fact that, up to ES5, there's been no agreement on which name to use for the equality function and no default implementation for it it's of no excuse to avoid the issue. It's their (the people who standardized it) Map type, and they shou…
> You can still iterate through all the properties of an object and recursively implement equality on them this way. Can't do that for a hashmap since the value can change (by mutating the object) the hash would have to change as well and the object would have to move around. Not a sane proposition.
On top of that, the Map implementation could always call Object.freeze() on the keys that it receives