-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter13_generators_yield.js
42 lines (35 loc) · 1.42 KB
/
chapter13_generators_yield.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// function* myGenerator() {
// console.log('a');
// yield 1;
// console.log('b');
// yield 2;
// console.log('c');
// yield 3;
// console.log('d');
// yield 4;
// }
// const iter = myGenerator();
// iter; // { [Iterator] }
// console.log(iter.next()); // { value: 1, done: false }
// console.log(iter.next()); // { value: 2, done: false }
// console.log(iter.next()); // { value: 3, done: false }
// console.log(iter.next()); // { value: 4, done: false }
// console.log(iter.next()); // { value: undefined, done: true }
function* myGenerator() {
console.log('a');
yield 1;
return;
console.log('b');
yield 2;
console.log('c');
yield 3;
console.log('d');
yield 4;
}
const iter = myGenerator();
iter; // { [Iterator] }
console.log(iter.next()); // { value: 1, done: false }
console.log(iter.next()); // { value: undefined, done: true }
console.log(iter.next()); // { value: undefined, done: true }
console.log(iter.next()); // { value: undefined, done: true }
console.log(iter.next()); // { value: undefined, done: true }