-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path3-async.js
More file actions
50 lines (39 loc) · 958 Bytes
/
3-async.js
File metadata and controls
50 lines (39 loc) · 958 Bytes
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
43
44
45
46
47
48
49
50
'use strict';
async function inc(a) {
return a + 1;
}
const sum = async function (a, b) {
return a + b;
};
const max = async (a, b) => (a > b ? a : b);
const avg = async (a, b) => {
const s = await sum(a, b);
return s / 2;
};
const obj = {
name: 'Marcus Aurelius',
async split(sep = ' ') {
return this.name.split(sep);
},
};
class Person {
constructor(name) {
this.name = name;
}
static async of(name) {
return await new Person(name);
}
async split(sep = ' ') {
return this.name.split(sep);
}
}
const person = new Person('Marcus Aurelius');
const main = async () => {
console.log('await inc(5) =', await inc(5));
console.log('await sum(1, 3) =', await sum(1, 3));
console.log('await max(8, 6) =', await max(8, 6));
console.log('await avg(8, 6) =', await avg(8, 6));
console.log('await obj.split() =', await obj.split());
console.log('await person.split() =', await person.split());
};
main();