-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1-async-gen.js
More file actions
38 lines (29 loc) · 1.07 KB
/
1-async-gen.js
File metadata and controls
38 lines (29 loc) · 1.07 KB
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
'use strict';
// Generator function
function* genFn(x) {
yield x * 2;
return x * 3;
}
async function* asyncGenFn(x) {
yield x * 2;
return x * 3;
}
const asyncGenFn2 = async function* (x) {
yield x * 2;
return x * 3;
};
console.log('genFn(5) =', genFn(5));
console.log('asyncGenFn =', [asyncGenFn]);
console.log('asyncGenFn.toString() =', [asyncGenFn.toString()]);
console.log('typeof asyncGenFn =', typeof asyncGenFn);
const fnProto = Object.getPrototypeOf(asyncGenFn);
console.log('fnProto.constructor.name =', fnProto.constructor.name);
console.log('typeof asyncGenFn(5) =', typeof asyncGenFn(5));
console.log('asyncGenFn(5).toString() =', asyncGenFn(5).toString());
const genProto = Object.getPrototypeOf(asyncGenFn(5));
console.log('genProto =', genProto);
console.log('genProto[Symbol.asyncIterator] =', genProto[Symbol.asyncIterator]);
console.log('asyncGenFn(5) =', asyncGenFn(5));
console.log('asyncGenFn(5).next() =', asyncGenFn(5).next());
console.log('asyncGenFn(5).next().value =', asyncGenFn(5).next().value);
console.log('asyncGenFn2(5) =', asyncGenFn2(5));