I think MDN has a good comparison: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The only real downside of maps is that they don't support JSON serialization. However you can fix this pretty easily by using a map with an overridden `toJSON` for serializable keys.
class StringMap extends Map {
toJSON() {
return Object.fromEntries(this);
}
} node.querySelectorAll('tr[data-selected="true"]');
In other words.. "use the DOM to handle the DOM."This wouldn't work if you need to know the order of the properties.
I was recently refactoring some code and wondering whether to use a (JS) class… The search results were mostly about React Class Components. And I was contemplating building a reusable component… results from the past decade were split between React Components and Web components. (In retrospect I should’ve tried DDG or something not connected to my search history lol).
Anyway where are the vanilla JS/TS DOM manipulators blogging these days? I guess here is one, thankful for the post :)
In my opinion, DOM nodes should be disposable. A means to display data through the browser, not more. I avoid storing custom data on them, I avoid association like in the blog post. 98% of the time, you just want a simple transform from domain data into DOM nodes, for display. You really don't want to care which DOM nodes. This is how React works, and the reason why it is successful.
Granted, once you get into the hundreds of elements updated at interactive rates, you may have to mess with the DOM directly, because you can't trust React to be smart about it. That's still just a consequence of DOM being terribly inefficient for historical reasons.
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