Created
January 14, 2020 18:25
-
-
Save r3dm1ke/2f3d0c0bb19c93b3ecda4270cac997e9 to your computer and use it in GitHub Desktop.
Using global symbol registry in ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const sym1 = Symbol.for('some-key'); // Symbol is created in global registry | |
| // Elsewhere in project: | |
| const sym2 = Symbol.for('some-key'); // Symbol is retrieved from global registry | |
| // They are the same symbol: | |
| console.log(sym1 === sym2); // true | |
| // You can even access the key property: | |
| console.log(Symbol.keyFor(sym1)); // some-key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment