wuxianqiang / blog

博客系列
17 stars 4 forks source link

异步代码的面试题 #260

Open wuxianqiang opened 4 years ago

wuxianqiang commented 4 years ago
console.log('script start')
new Promise((resolve, reject) => {
  console.log('promise1')
  resolve()
}).then(() => {
  console.log('then11')
  new Promise((resolve, reject) => {
    console.log('promise2')
    resolve()
  }).then(() => {
    console.log('then2-1')
  }).then(() => {
    console.log('then2-2')
  })
}).then(() => {
  console.log('then12')
}).then(() => {
  console.log('then13')
})
console.log('script end')

答案

script start
promise1
script end
then11
promise2
then2-1
then12
then2-2
then13