The few times that I've used objects as keys in a map I did it to store metadata about that specific object. I've always used a WeakMap
for this because of the benefit of the entry in the map being garbage collected automatically when the object it was using as a key gets garbage collected.
Storing metadata is the only use case I can think of for objects as keys in maps, but I'm curious if there are other use cases for objects as keys and if in those cases, you'd use a regular Map
over a WeakMap
.