首页 > 其他 > 详细

03回调函数

时间:2020-06-26 16:52:08      阅读:60      评论:0      收藏:0      [点我收藏+]
//回调函数
doSomeThing(result => {
  doSomeThingElse(result, newResult => {
    doSomeThingThird(newResult, finalResult => {
      console.log(finalResult)
    }, errCallback)
  }, errCallback)
}, errCallback)

// promise嵌套
doSomeThing()
  .then(result => {
    return doSomeThingElse(result)
  })
  .then(newResult => {
    return doSomeThingThird(newResult)
  })
  .then(finalResult => {
    console.log(finalResult)
  })
  .catch(err => {
    console.log(err);

  })
//异常穿透,只需要指定一个catch



async function request() {
  try {
    const result = await doSomeThing()
    const newResult = await doSomeThingElse(result)
    const finalResult = await doSomeThingThird(newResult)
    console.log(‘finalResult: ‘, finalResult);
  } catch (error) { //异常穿透
    errCallback(error) 
  }

}
let errCallback = error => {
  console.log(error)
}

 

03回调函数

原文:https://www.cnblogs.com/xiaoliziaaa/p/13195250.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!