Re:ES6 in Depth – Symbols
by artursapek on Friday June 12, 2015 @11:33AM
(#9706498)
This was the one thing I didn't understand. Why is using a global Symbol registry any better than just using string properties like usual?
[ Parent
| on HN ]
Re:ES6 in Depth – Symbols
by Ded7xSEoPKYNsDd on Friday June 12, 2015 @12:02PM
(#9706717)
There won't be a problem if the string happens to be e.g. "toString", I guess. Although they added a 'Map' for that, too.
s1 = Symbol("cat");
s2 = Symbol.for("cat");
s3 = Symbol.for("cat");
s1 == s2; // false
s2 == s3; // true
You can still have Symbols outside the registry.
Re:ES6 in Depth – Symbols
by artursapek on Saturday June 13, 2015 @09:24PM
(#9713460)
That I understand. What I don't understand is why s2 and s3 shouldn't just be vanilla strings.