Skip to content

Comment on Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes

Comments

Why did they not make the map assigning syntax as convenient as with objects, instead going for the clunky get/set?

Because a Map is an Object. It has properties and methods. The only way to provide a safe and clean namespace for your keys is to provide an explicit API. It also supports keys that can be not only strings or symbols.

Several things such as standard way for adding, removing and checking for keys, built-in size property, extensibility.

You think "key in object" is better than "maaaaap.has(key)"? I don't because it's unpredictable and prone to exceptions.

Give them a try. It's not a complete replacement for regular old objects

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.