4 ms·
`Symbol.for` uses a global registry and the whole thing is "stringly typed". Looks like an anti-pattern to me. If you want one particular symbol from some lib
by ahoge 11y ago
`Symbol.for` uses a global registry and the whole thing is "stringly typed".
Looks like an anti-pattern to me.
If you want one particular symbol from some library, you could import it.
- artursapek 11y agoThis was the one thing I didn't understand. Why is using a global Symbol registry any better than just using string properties like usual?
- Ded7xSEoPKYNsDd 11y agoThere won't be a problem if the string happens to be e.g. "toString", I guess. Although they added a 'Map' for that, too.
- towelguy 11y agos1 = Symbol("cat"); s2 = Symbol.for("cat"); s3 = Symbol.for("cat"); s1 == s2; // false s2 == s3; // true You can still have Symbols outside the registry.
- artursapek 11y agoThat I understand. What I don't understand is why s2 and s3 shouldn't just be vanilla strings.