1const async1 = async () => { 2 console.log('async1'); 3 setTimeout(() => { 4 console.log('timer1') 5 }, 2000) 6 await new Promise(resolve => { 7 console.log('promise1') 8 }) 9 console.log('async1 end') 10 return 'async1 success' 11} 12console.log('script start'); 13async1().then(res => console.log(res)); 14console.log('script end'); 15Promise.resolve(1) 16 .then(2) 17 .then(Promise.resolve(3)) 18 .catch(4) 19 .then(res => console.log(res)) 20setTimeout(() => { 21 console.log('timer2') 22}, 1000) 23
参考答案:
需要注意的点:
new Promise
要是没有返回值的话则不执行后面的内容'script start'
'async1'
'promise1'
'script end'
1
'timer2'
'timer1'
最近更新时间:2022-01-09