4 ms·
The language is good at creating literal objects of no particular type/class/prototype. The concept of a Set is closer to an Array of unique Numbers than one of
by samtho 3y ago
The language is good at creating literal objects of no particular type/class/prototype. The concept of a Set is closer to an Array of unique Numbers than one of literal objects:
const s = new Set([1,2,3]);
The resulting instance of Set can be queried for something existing in the set, have items added to the set, and remove from the set. This doesn’t handle literal objects (e.g. a record) well, which isn’t idiosyncratic to JS as most languages treat objects as reference-ish. The solution be to use a literal String or Number identifier that can be looked up.
I’m genuinely curious, what features from other languages do you want to see in this implementation?
- leosanchez 3y ago> I’m genuinely curious, what features from other languages do you want to see in this implementation? In Java and C# you can override equals method in which you specify which property to check equality on, (even python you can do that with __eq__ i think). In JavaScript you are left with either primitives or objects with references equality checks.
- samtho 3y agoThat’s fair, I would actually love to have a ‘Symbol.compare’ to implement so instances can be sorted and checked for equality.