Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created January 14, 2020 18:25
Show Gist options
  • Select an option

  • Save r3dm1ke/2f3d0c0bb19c93b3ecda4270cac997e9 to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/2f3d0c0bb19c93b3ecda4270cac997e9 to your computer and use it in GitHub Desktop.
Using global symbol registry in ES6
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