async function async1 () {
console.log('async1 start')
await async2()
console.log('async1 end')
}
async function async2 () {
console.log('async2')
setTimeout(() => {
console.log('async2 setTimeout')
},0)
}
console.log('script start')
async1()
setTimeout(() => {
console.log('setTimeout')
},0)
new Promise((resolve) => {
console.log('promise1')
resolve()
}).then(() => {
console.log('promise2')
})
console.log('script end')
function async1 () {
console.log('async1 start')
return function async2 () {
return new Promise((resolve) => {
console.log('async2')
resolve()
setTimeout(() => {
console.log('async2 setTimeout')
},0)
}).then(() => {
console.log('async1 end')
})
}
}
console.log('script start')
async1()()
setTimeout(() => {
console.log('setTimeout')
},0)
new Promise((resolve) => {
console.log('promise1')
resolve()
}).then(() => {
console.log('promise2')
})
console.log('script end')
// 控制台的输出
// script start
// async1 start
// async2
// promise1
// script end
// async1 end
// promise2
// sync2 setTimeout
// setTimeout