Hacker News new | past | comments | ask | show | jobs | submit login

What's the point of "Map" and "Set" in Javascript? Objects can already act like either.



* 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.


You 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.


Also see 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)


Objects can only have String keys. Maps and Sets can have arbitrary object keys.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: