Promise3

作者: 加冰宝贝 | 来源:发表于2018-06-21 20:33 被阅读3次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // 结论
    // 1 .错误不会被重复铺获;
    // 2 .catch返回一个promise实例,并且 是resolve的状态
    // 3 .抛出错误变为reject状态,所以绕过了两个then直接
    // 跑到最下面catch
    console.log("here we go...");
    new Promise(resolve => {
        setTimeout(()=>{
            resolve();
        },2000)
    })
        .then(()=>{
            console.log("start");
            throw new Error ("test error")
        })
        .catch(err=>{
            console.log("I catch:",err)
            throw new Error("another error")
        })
        .then(()=>{
            console.log("arrive here!");
        })
        .then(()=>{
            console.log("here...")
        })
        .catch(err =>{
            console.log("No ,I Catch:",err)
        })
</script>
</body>
</html>

相关文章

  • 手动实现 Promise.all 与 Promise.race

    原文:https://github.com/xieranmaya/Promise3/blob/master/Pro...

  • promise3

    等待它resolve then的语法糖 不管成功失败都会调用 不想两次都调用同一个函数就可以用

  • Promise3

  • Angular笔记 处理异步

    目前常见的异步编程的几种方法:1、回调函数2、Promise3、Rxjs4、事件监听/发布订阅 一、函数回调 回调...

  • 03 Promise3 链式流

    3.4 链式流 可把多个Promise连接到一起以表示一系列异步步骤。这种方式可实现的关键在于以下两个Promis...

网友评论

    本文标题:Promise3

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