Promise

2021-12-30  本文已影响0人  xueyueshuai
let a = 3
console.log('a', a)

let pp = new Promise(function (resolve, reject) {
  setTimeout(() => {
    if (a == 1) {
      resolve(a)
    }
    if (a == 2) {
      reject(a)
    }
    if (a == 3) {

    }
  })
})

pp.then((res) => {
  console.log('res', res)
}).catch(err => {
  console.log('err', err)
}).finally(() => {
  console.log('finally')
})

// a 1
// res 1 
// finally

// a 2
// err 2
// finally

// a 3
上一篇下一篇

猜你喜欢

热点阅读