marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.03k stars 799 forks source link

Ch. 6, Maps #366

Closed dhollinden closed 6 years ago

dhollinden commented 6 years ago

I'm not able to understand what this is implying:

"However, because property names are strings, this still doesn’t help when your key values are of some other type."

For me, and possibly other newbie readers, it'd be helpful to have an example that illustrates the problem.

Thanks

mikegowen commented 6 years ago

I tripped up on this as well, and @marijnh already made some changes to the text. But I might suggest this for further clarification:

Because property names must be strings, this still doesn’t help when your key values are of some other type.

But this solution doesn't address another constraint of using plain objects as maps – that object property names must be strings. If you'd like your key values to be of a different type, this approach will not work.

Or something like that. I think the confusion is that the current verbiage makes it feel too closely linked to the previous paragraph, when it's somewhat of a different issue. I could be wrong. Feel free to ignore :)

marijnh commented 6 years ago

I hope attached patch helps with the string-key paragraph.

dhollinden commented 6 years ago

That does help. Thanks!