Last active
June 19, 2016 10:52
-
-
Save mizdra/b9e7cce7daac99f2e328c2ef9202a211 to your computer and use it in GitHub Desktop.
IterableIteratorの挙動テスト。
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
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