Maps vs Objects in ES6, When to use?

后端 未结 6 1741
醉酒成梦
醉酒成梦 2020-11-28 21:55

Ref: MDN Maps

Use maps over objects when keys are unknown until run time, and when all keys are the same type and all values are the same type.

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 22:28

    Use maps over objects when keys are unknown until run time, and when all keys are the same type and all values are the same type.

    I have no idea why someone would write something so obviously wrong. I have to say, people are finding more and more wrong and/or questionable content on MDN these days.

    Nothing in that sentence is correct. The main reason to use maps is when you want object-valued keys. The idea that the values should be the same type is absurd--although they might be, of course. The idea that one shouldn't use objects when keys are unknown until run time is equally absurd.

提交回复
热议问题