Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58ace58

Browse files
Use yield* for array and generator
1 parent 8cc7a73 commit 58ace58

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎JavaScript/g-yield-star.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
function* genFn() {
4+
yield* [10, 20, 30];
5+
}
6+
7+
const c = genFn();
8+
const val1 = c.next();
9+
const val2 = c.next();
10+
const val3 = c.next();
11+
const val4 = c.next();
12+
console.log({ c, val1, val2, val3, val4 });

‎JavaScript/h-yield-gen.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
function* gen1() {
4+
yield 10;
5+
yield 20;
6+
yield 30;
7+
}
8+
9+
function* gen2() {
10+
yield 40;
11+
yield 50;
12+
yield 60;
13+
}
14+
15+
function* genFn() {
16+
yield* gen1();
17+
yield* gen2();
18+
}
19+
20+
console.log('[...genFn()] =', [...genFn()]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /