Created
December 27, 2019 11:23
-
-
Save behnamazimi/f34c3dc0110200c257f612338cbf8d37 to your computer and use it in GitHub Desktop.
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 }; | |
}, | |
[Symbol.iterator]: function() { | |
this.pointerIndex = 0; | |
return { next: this.next.bind(this) } | |
} | |
} | |
for (let item of data) { | |
console.log(item) | |
} //o: A B C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment