2 ms·
Because it is impossible in JS? Except some crazy hacks, similar to how Java's constant string pool works, where every used object is a reference to a value in
by ivanjermakov 2y ago
Because it is impossible in JS? Except some crazy hacks, similar to how Java's constant string pool works, where every used object is a reference to a value in a pool of all objects.
- jdkoeck 2y agoI wouldn’t call this a particularly crazy hack, it’s also called string interning and I reckon that’s what every language runtime does when strings are immutable (which includes javascript runtimes, also this isn’t required by the language specification).
- nikeee 2y agoThere is the record and tuple proposal. If we'd have methods on records (currently not part of the spec) this would be trivial.