zoukankan      html  css  js  c++  java
  • promise 执行顺序

    1、代码

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>promise 执行</title>
        </head>
        <body>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
            <script type="text/javascript">
                function delay(time) {
                    return new Promise(function(resolve, reject) {
                        setTimeout(resolve, time)
                    })
                }
                delay(1000)
                    .then(function step2() {
                        console.log('step 2: after 1000ms');
                        return delay(2000)
                    })
                    .then(function step3() {
                        console.log('step 3: after another 2000ms');
                    })
                    .then(function step4() {
                        console.log('step 4: next job');
                        return delay(5000)
                    })
                    .then(function step5() {
                        console.log('step 5: after another 5000ms');
                    })
            </script>
        </body>
    </html>

    控制台输出:

    2、说明

    promise将执行结果(不管是resolve还是reject),传到then和catch中。

  • 相关阅读:
    3、生成证书请求文件
    2、申请苹果App ID
    登录iOS Dev Center
    SQL Server 合并行
    asp 月末 月初
    linux
    ASP数组全集,多维数组和一维数组[转]
    oracle 秒
    oracle 存储过程 包 【转】
    linux
  • 原文地址:https://www.cnblogs.com/mengfangui/p/9921455.html
Copyright © 2011-2022 走看看