Promise

作者: xueyueshuai | 来源:发表于2021-12-30 14:41 被阅读0次
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

相关文章

网友评论

      本文标题:Promise

      本文链接:https://www.haomeiwen.com/subject/qsbiqrtx.html