Created
December 27, 2019 11:23
-
-
Save behnamazimi/d7b73237abdea4e48bc00aa7f2c7f609 to your computer and use it in GitHub Desktop.
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
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 }; | |
} | |
} | |
const it = data[Symbol.iterator]; | |
console.log(it()) //o: {value: "A", done: false} | |
console.log(it()) //o: {value: "B", done: false} | |
console.log(it()) //o: {value: "C", done: false} | |
console.log(it()) //o: {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment