|
1 | 1 | // 面试题目一
|
2 | 2 |
|
3 |
| -async function async1() { |
4 |
| - console.log('async1 start') // 2 |
5 |
| - await async2() |
6 |
| - console.log('async1 end') // 7 |
7 |
| -} |
| 3 | +function events() { |
| 4 | + async function async1() { |
| 5 | + console.log('async1 start') // 2 |
| 6 | + await async2() |
| 7 | + console.log('async1 end') // 7 |
| 8 | + } |
8 | 9 |
|
9 |
| -async function async2() { |
10 |
| - console.log('async2') // 3 |
11 |
| -} |
| 10 | + async function async2() { |
| 11 | + console.log('async2') // 3 |
| 12 | + } |
12 | 13 |
|
13 |
| -console.log('script start') // 1 |
| 14 | + console.log('script start') // 1 |
14 | 15 |
|
15 |
| -setTimeout(function () { |
16 |
| - console.log('setTimeout0') |
17 |
| -}, 0) // 12 |
| 16 | + setTimeout(function () { |
| 17 | + console.log('setTimeout0') |
| 18 | + }, 0) // 12 |
18 | 19 |
|
19 |
| -setTimeout(function () { |
20 |
| - console.log('setTimeout2') |
21 |
| -}, 300) // 13 |
| 20 | + setTimeout(function () { |
| 21 | + console.log('setTimeout2') |
| 22 | + }, 300) // 13 |
22 | 23 |
|
23 |
| -setImmediate(() => console.log('setImmediate')) // 11 |
| 24 | + setImmediate(() => console.log('setImmediate')) // 11 |
24 | 25 |
|
25 |
| -process.nextTick(() => console.log('nextTick1')) // 9 |
| 26 | + process.nextTick(() => console.log('nextTick1')) // 9 |
26 | 27 |
|
27 |
| -async1() // 2 |
| 28 | + async1() // 2 |
28 | 29 |
|
29 |
| -new Promise(function (resolve) { |
30 |
| - console.log('promise1') // 4 |
31 |
| - resolve() |
32 |
| - console.log('promise2') // 5 |
33 |
| -}).then(function () { |
34 |
| - console.log('promise3') // 8 |
35 |
| -}) |
| 30 | + new Promise(function (resolve) { |
| 31 | + console.log('promise1') // 4 |
| 32 | + resolve() |
| 33 | + console.log('promise2') // 5 |
| 34 | + }).then(function () { |
| 35 | + console.log('promise3') // 8 |
| 36 | + }) |
36 | 37 |
|
37 |
| -process.nextTick(() => console.log('nextTick2')) // 10 |
| 38 | + process.nextTick(() => console.log('nextTick2')) // 10 |
38 | 39 |
|
39 |
| -console.log('script end') // 6 |
| 40 | + console.log('script end') // 6 |
| 41 | +} |
| 42 | +// events() |
40 | 43 |
|
41 | 44 | /**
|
42 | 45 | * script start
|
|
0 commit comments