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 data = ["A", "B", "C"]; | |
| for (let item of data) { | |
| console.log(item) | |
| } //o: A B C |
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 data = { | |
| items: ["A", "B", "C"], | |
| pointerIndex: 0, | |
| next() { | |
| if (this.pointerIndex < this.items.length) // if not done | |
| return { value: this.items[this.pointerIndex++], done: false } | |
| else // if done | |
| return { value: undefined, done: true }; | |
| } | |
| } |
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
| let dataElement = data.next(); | |
| while (!dataElement.done) { | |
| console.log(dataElement.value) | |
| dataElement = data.next(); | |
| } //o: A B C |
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
| console.log(data.next()) //o: {value: "A", done: false} | |
| console.log(data.next()) //o: {value: "B", done: false} | |
| console.log(data.next()) //o: {value: "C", done: false} | |
| console.log(data.next()) //o: {value: undefined, done: true} |
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 data = { | |
| items: ["A", "B", "C"], | |
| pointerIndex: 0, | |
| next() { | |
| if (this.pointerIndex < this.items.length) // if done | |
| return { value: this.items[this.pointerIndex++], done: false } | |
| else // if not done | |
| return { value: undefined, done: true }; | |
| } | |
| } |
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 symblOne = Symbol("Description"); | |
| const symblTwo = Symbol("Description"); | |
| symblOne === symblTwo //o: false |
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 symblOne = Symbol(); | |
| const myObject = { | |
| [symblOne]: "My Data", | |
| //... | |
| } | |
| console.log(myObject[symblOne]) //o: "My Data" |
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 myObject = { | |
| [Symbol()]: "My Data", | |
| //... | |
| } | |
| console.log(myObject) //o: {Symbol(): "My Data"} |
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 myObject = { | |
| [Symbol("myKey")]: "My Data", | |
| //... | |
| } | |
| console.log(Object.getOwnPropertySymbols(myObject)); //o: [Symbol(myKey)] | |
| const symbl = Object.getOwnPropertySymbols(myObject)[0] | |
| console.log(myObject[symbl]) //o: "My Data" |
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 data = { | |
| items: ["A", "B", "C"], | |
| pointerIndex: 0, | |
| [Symbol.iterator]: function () { | |
| if (this.pointerIndex < this.items.length) // if done | |
| return { value: this.items[this.pointerIndex++], done: false } | |
| else // if not done | |
| return { value: undefined, done: true }; | |
| } | |
| } |