having to significantly refactor this code because turns out i probably actually do want `Object.create(null)` instead of `Map` and `Array.from()` instead of `Set`

@Lady oh i just mean i have no idea in what context this would make sense to say (though i’m sure it exists)

@aescling Map and Set are always mutable and do not participate in general JavaScript property access semantics (enumerability, writability, etc.)

[there is a proposal for readonly Maps and Sets but it’s still only Stage 1]

when you do actually want to take advantage of javascript property semantics (enumerability, writability, getters/setters), you need to use ordinary objects to do it. `Object.create(null)` is a great way to do this when you only need the property semantics and not the prototype chain.

Follow

@aescling in my case, it is very important that my mappings do not change after object creation, which is easy to achieve on ordinary objects with `Object.freeze()` but impossible to guarantee with Maps. since my keys are all strings, `Object.create(null)` is the simplest and most straightforward approach.

· · Web · 1 · 0 · 0
Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.