This file contains 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
var obj = {}; | |
obj[Symbol.iterator] = function* () {yield 'Hatfield', yield 'Ulrich', yield 'Hammet'}; | |
console.log(...obj); // Hatfield Ulrich Hammet |
This file contains 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
var obj = {}; | |
obj[Symbol.for('name')] = 'Jordan'; | |
console.log(obj); // {Symbol(name): "Jordan"} | |
obj[Symbol.for('name')] = 'Jordan'; // Idempotent? Yes. | |
console.log(obj); // {Symbol(name): "Jordan"} |
This file contains 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
var obj = {}; | |
obj[Symbol('name')] = 'Jordan'; | |
console.log(obj); // {Symbol(name): "Jordan"} | |
obj[Symbol('name')] = 'Jordan'; // Idempotent? | |
console.log(obj); // {Symbol(name): "Jordan", Symbol(name): "Jordan"} |
This file contains 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
var s1 = Symbol('foo'); // local symbol for 'foo' | |
var s2 = Symbol.for('foo'); // global symbol for 'foo' | |
s1 === s2 // false |
This file contains 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
var s1 = Symbol.for('s'); // creates a unique Global Symbol | |
var s2 = Symbol.for('s'); // fetches existing Global Symbol | |
s1 === s2 // true |
This file contains 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
var s1 = Symbol('s'); // creates a unique local Symbol (not Global) | |
var s2 = Symbol.for('s'); // creates Global Symbol instance accessible from anywhere at runtime | |
s1 === s2 // false |
This file contains 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
var s = Symbol.for('random_string') | |
console.log(s); // Symbol(random_string) |
This file contains 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
var s = Symbol('foo'); | |
Symbol.for('foo'); // Symbol(foo) |
This file contains 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
var s = Symbol('foo'); | |
alert(s); // Uncaught TypeError: Cannot convert a Symbol value to a string | |
// use alert(s.toString()) or alert(s.description) instead |
This file contains 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
var s = Symbol('foo'); | |
alert(s); // Uncaught TypeError: Cannot convert a Symbol value to a string |
NewerOlder