zoukankan      html  css  js  c++  java
  • promise.then( )返回的新promise的结果状态由什么决定?

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>promise</title>
    </head>
    <body>
        <script>
      
        // promise.then( )返回的新promise的结果状态由什么决定?
        // (1)简单表达:由then()指定的回调函数执行的结果决定
        // (2)详细表达:
        // @如果抛出异常,新promise变 为rejected, reason为抛出的异常
        // ②如果返回的是非promise的任意值,新promise 变为resolved, value 为返回的值
        // ③如果返回的是另一 个新promise,此promise的结果就会成为新promise的结果
    
    
        new Promise((resolve,reject) =>{
            resolve(1)
        })
        .then(value1 =>{
            console.log('onResolve1()',value1)
            // return undefined
            // return Promise.resolve(222)
             throw 6
            // return
            //什么都不写就相当于返回一个undefined
        },reason1 =>{
            console.log('onRejectd1()',reason1)
        })
        .then(value2 =>{
            console.log('onResolve2()',value2)
            
        },reason2 =>{
            console.log('onRejectd2()',reason2)
        })
        .then(value3 =>{
            console.log('onResolve3()',value3)
        },reason3 =>{
            console.log('onRejectd3()',reason3)
        })
        </script>
    </body>
    </html>
    

      

  • 相关阅读:
    oracle12 安装
    ORACLE重装之后恢复数据库,相当于sqlserver的附加数据库
    git
    P1323 删数游戏(技巧)
    P2486 【SDOI2011】 染色
    P1084 【NOIP 2012】 疫情控制
    前缀、中缀、后缀表达式
    【P1979】 NOIP2013 华容道
    P2601 【ZJOI2009】对称的正方形
    NOIP2015 运输计划
  • 原文地址:https://www.cnblogs.com/malong1992/p/13697935.html
Copyright © 2011-2022 走看看