Skip to content

Instantly share code, notes, and snippets.

@mizdra
Last active June 19, 2016 10:52
Show Gist options
  • Save mizdra/b9e7cce7daac99f2e328c2ef9202a211 to your computer and use it in GitHub Desktop.
Save mizdra/b9e7cce7daac99f2e328c2ef9202a211 to your computer and use it in GitHub Desktop.
IterableIteratorの挙動テスト。
function* gen() {
let i = 0;
while(true) {
yield i++;
}
}
const g1 = gen();
console.log(g1.next()); // { value: 0, done: false }
const g2 = g1[Symbol.iterator]();
console.log(g2.next()); // { value: 1, done: false }
const g3 = g2[Symbol.iterator]();
console.log(g3.next()); // { value: 2, done: false }
const g4 = g1[Symbol.iterator]();
console.log(g4.next()); // { value: 3, done: false }
console.log(g1 === g1[Symbol.iterator]()); // true
const g5 = g1[Symbol.iterator]()[Symbol.iterator]();
console.log(g5.next()); // { value: 4, done: false }
const g6 = gen();
console.log(g6.next()); // { value: 0, done: false }
console.log(gen() === gen()); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment