3 ms·
Implementing this on mutable objects is a dangerous game. That would be quite the footgun (and JS has plenty of them already). IMHO it's better to be explicit
by Gare 3y ago
Implementing this on mutable objects is a dangerous game. That would be quite the footgun (and JS has plenty of them already).
IMHO it's better to be explicit in such a case. It's not complicated to implement your own set-like class that does exactly what you want.
- leosanchez 3y ago> That would be quite the footgun Could you explain why that would be a footgun? JavaScript already has known Symbols like hasInstance which is kind of similar to this.
- Gare 3y agoIt's very important to ensure that the value of hash for a given entity doesn't change if it is to be relied upon, otherwise things like Map or Set will not function properly. Therefore, one should be very careful in implementing it yourself and ideally one should use immutable hashable structures provided by the language/stdlib (like tuples or sets in Python). Until Javascript has such structures which should be enough for majority of use cases (there is record and tuple language proposal, but it's in limbo) I think it's unwise to provide a way to sloppily emulate it in user code.