Created
October 5, 2016 16:30
-
-
Save ZhihaoLau/f6b961201bb95f6044048379c980a825 to your computer and use it in GitHub Desktop.
ES6 method shorthand generator
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 o = { | |
*createIterator(items) { | |
for (let i = 0; i < items.length; i++) { | |
yield items[i]; | |
} | |
} | |
}; | |
let it = o.createIterator([1, 2, 3]); | |
console.log(it.next()); // Object {value: 1, done: false} | |
console.log(it.next()); // Object {value: 2, done: false} | |
console.log(it.next()); // Object {value: 3, done: false} | |
console.log(it.next()); // Object {value: undefined, done: true} | |
console.log(it.next()); // Object {value: undefined, done: true} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment