3 ms·
What's the point of "Map" and "Set" in Javascript? Objects can already act like either.
by rorrr 14y ago
What's the point of "Map" and "Set" in Javascript? Objects can already act like either.
- wycats 14y agoObjects can only have String keys. Maps and Sets can have arbitrary object keys.
- paulrouget 14y agoYou can only have a string as a key if you use Object. You'd need to build hash for the key then. And that makes things much more complex.
- masklinn 14y ago* Objects as maps have limitations: only string keys, and literal objects have a prototype so you inherit potentially risky properties/behaviors * Objects as sets are kinda terrible, they're not syntactically awesome and you need to override #toString to make them work correctly. They also don't support any set operation which sucks.
- shabble 14y agoAlso see http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/ http://www.devthought.com/2012/01/18/an-object-is-not-a-hash... from earlier about some pitfalls that you might not immediately consider. (HN Thread: https://news.ycombinator.com/item?id=4629544 https://news.ycombinator.com/item?id=4629544)