tc39 / proposal-accessible-object-hasownproperty

Object.hasOwn() proposal for ECMAScript
https://tc39.es/proposal-accessible-object-hasownproperty/
MIT License
134 stars 8 forks source link

Suggested Q&A entry: why not use `Map`s? #1

Closed mathiasbynens closed 3 years ago

mathiasbynens commented 3 years ago

Which use cases of objects-as-dictionaries are not better handled by using Maps?

jamiebuilds commented 3 years ago

I think until its common practice to serialize/deserialize JSON using Map (which is already possible today with the JSON.parse/stringify methods, but as far as I can tell is not popular) we're going to continue to see lots of code make use of objects-as-dictionaries. Searching through public usage of libraries that provide has(o, p) you'll find lots of examples of using has() with request/json-body data.

zloirock commented 3 years ago

Until Map and Set literals appear, Object and Array will be used more frequently due to the ease of declaration even if Map and Set are more suitable data structures.

ljharb commented 3 years ago

All the arguments for adding Object.fromEntries apply here; just like the existence of Set didn't obviate arrays-as-sets, the existence of Map doesn't obviate objects-as-dictionaries.

mathiasbynens commented 3 years ago

For the record, I agree with everything you're saying, and have written about it before: https://v8.dev/features/object-fromentries#objects-vs.-maps I'm merely suggesting to document this rationale in the FAQ to get ahead of the debate :) (Same with the other issue I filed.)

jamiebuilds commented 3 years ago

Yup, I was just trying to work out the reasoning in issues before committing them to the explainer doc