Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by eviks on Saturday May 06, 2023 @12:42AM
(#35838085)
Why did they not make the map assigning syntax as convenient as with objects, instead going for the clunky get/set?
[ Parent
| on HN ]
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by panzerboiler on Saturday May 06, 2023 @03:19AM
(#35839017)
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.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by beebeepka on Saturday May 06, 2023 @03:45AM
(#35839139)
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