Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more complete statement for Map #1773

Open
wants to merge 1 commit into
base: 2nd-ed
Choose a base branch
from

Conversation

DBadalyan
Copy link

@DBadalyan DBadalyan commented Dec 28, 2021

Please type "I already searched for this issue":
I already searched for this issue
Edition: (pull requests not accepted for previous editions)
2-nd edition
Book Title:
Get Started
Chapter:
Chapter 3: Digging to the Roots of JS
Section Title:
Iteration -> Iterables
Topic:
Fixed statement about Map keys.

@DBadalyan DBadalyan changed the title Update ch3.md fix: more complete statement for Map Dec 28, 2021
@getify
Copy link
Owner

getify commented Dec 28, 2021

The assertion in the text comes from:

  1. Using a Map with primitive keys is generally wasteful, as it's probably less efficient than just using a normal object. The conventional wisdom is, use a plain object unless you need object/function keys, in which case you use a Map. I didn't explain that nuance in the text, but I agree with that opinion and based my statement on it.
  2. The WeakMap(..) counterpart to Map(..) does in fact require only objects/functions as keys, so it's a frustrating gotcha if you've been in the habit of storing lots of non-object keys in Map and then you try to do so with a WeakMap and it fails.

@DBadalyan
Copy link
Author

I totally agree with your arguments, and they are indeed very important. I just disagree with an idea to have that statement in that way so it can be misused somehow via referencing.

I understand that this is not a reference book and despite that, it is even important to have very clear and complete statements, considering book's popularity among beginners.

Might be somehow it can be introduced by other way which already will emphasize notions you listed above.

Thanks for replay.

PS: not a big deal actually, just trying to be idealistic.

@getify getify force-pushed the 2nd-ed branch 2 times, most recently from 23d8b7b to e909d38 Compare July 16, 2022 14:49
@getify getify force-pushed the 2nd-ed branch 3 times, most recently from 29c2978 to 667c741 Compare August 3, 2022 14:27
@getify getify force-pushed the 2nd-ed branch 6 times, most recently from ec72a23 to 976d472 Compare August 24, 2022 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants