Created
February 22, 2016 03:55
-
-
Save raphaelpor/2465a69e440f1fa5dbf0 to your computer and use it in GitHub Desktop.
Lithium - Curso de ES2015 - Aula 11
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
//Ex 1 | |
function* idMaker() { | |
var index = 0 | |
while ( index < 3 ) | |
yield index++ | |
} | |
var gen = idMaker() | |
console.log( gen.next() ) // 0 | |
console.log( gen.next() ) // 1 | |
console.log( gen.next() ) // 2 | |
console.log( gen.next() ) // undefined | |
console.log( gen.next() ) // undefined | |
//Ex 2 | |
function* g1() { | |
yield 2 | |
yield 3 | |
yield 4 | |
} | |
function* g2() { | |
yield 1 | |
yield* g1() | |
yield 5 | |
} | |
var iterator = g2() | |
console.log( iterator.next() ) // { value: 1, done: false } | |
console.log( iterator.next() ) // { value: 2, done: false } | |
console.log( iterator.next() ) // { value: 3, done: false } | |
console.log( iterator.next() ) // { value: 4, done: false } | |
console.log( iterator.next() ) // { value: 5, done: false } | |
console.log( iterator.next() ) // { value: undefined, done: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment