Goodbye object literals too, apparently.
ES6 Maps are now on by default in Chrome 38
21–30 of 54 posts
Re: ES6 Maps are now on by default in Chrome 38
#22Re: ES6 Maps are now on by default in Chrome 38
#23 var map = {
a: 1,
b: 2,
c: 3
}
for (var key in map) {
console.log(map[key]);
}
outputs 1
2
3
in the console, like I expect.Re: ES6 Maps are now on by default in Chrome 38
#24You never had to use `hasOwnProperty()` to iterate a map. `Object.keys()` in conjunction with `Array.prototype.forEach()` works well for this. Example: var map = {a: '1', b: '2'} Object.keys(map).forEach(function(k) { console.log(map[k]) })
Re: ES6 Maps are now on by default in Chrome 38
#25Earlier quoted context omitted.
Maps have quite a few advantages over bare objects: * they have a length * their keys are typed, not limited to strings. Objects as keys actually works * they can be cleared in a single call * they can easily be iterated over keys, values or (key, value) pairs
I've searched but can't find the answer... Do they maintain insertion order?
> forEach calls callbackfn once for each key/value pair present in the map object, in key insertion order.
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ma...
Re: ES6 Maps are now on by default in Chrome 38
#26Why do you need to use .hasOwnProperty anyway? var map = { a: 1, b: 2, c: 3 } for (var key in map) { console.log(map[key]); } outputs 1 2 3 in the console, like I expect.
Re: ES6 Maps are now on by default in Chrome 38
#27Earlier quoted context omitted.
Maps have quite a few advantages over bare objects: * they have a length * their keys are typed, not limited to strings. Objects as keys actually works * they can be cleared in a single call * they can easily be iterated over keys, values or (key, value) pairs
I've searched but can't find the answer... Do they maintain insertion order?
Re: ES6 Maps are now on by default in Chrome 38
#28You never had to use `hasOwnProperty()` to iterate a map. `Object.keys()` in conjunction with `Array.prototype.forEach()` works well for this. Example: var map = {a: '1', b: '2'} Object.keys(map).forEach(function(k) { console.log(map[k]) })
To be fair `Object.keys()` is relatively recent and still needs to be shimmed for IE something to iterate over.
Re: ES6 Maps are now on by default in Chrome 38
#29Goodbye object literals too, apparently.
The intention is not to replace all 'map-like' uses of Object with Map. This MDN link explains clearly I think: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Use objects when there is logic that operates on individual elements.
Scroll down a bit and their first example is a Map with one string key, one object key and one function key...
I understand that Objects can only have keys that can be represented as a string. I do not understand why they say to use a Map when all keys are the same type and all values are the same type. Also, how would "logic that operates on individual elements" differ between a Map and an Object?
Re: ES6 Maps are now on by default in Chrome 38
#30Why do you need to use .hasOwnProperty anyway? var map = { a: 1, b: 2, c: 3 } for (var key in map) { console.log(map[key]); } outputs 1 2 3 in the console, like I expect.
Object.prototype.d = 4;
Now you'll get: 1
2
3
4