1async function async1 () { 2 console.log('async1 start'); 3 await new Promise(resolve => { 4 console.log('promise1') 5 resolve('promise resolve') 6 }) 7 console.log('async1 success'); 8 return 'async1 end' 9} 10console.log('srcipt start') 11async1().then(res => { 12 console.log(res) 13}) 14new Promise(resolve => { 15 console.log('promise2') 16 setTimeout(() => { 17 console.log('timer') 18 }) 19}) 20
参考答案:
这道题也不难,不过有一点需要注意的,在async1中的new Promise
resovle的值,和async1().then()
里的值是没有关系的,很多小伙伴可能看到resovle('promise resolve')
就会误以为是async1().then()
中的返回值。
'script start'
'async1 start'
'promise1'
'promise2'
'async1 success'
'async1 end'
'timer'
最近更新时间:2022-01-09