zoukankan      html  css  js  c++  java
  • 一个promise指定多个成功/失败的回调函数.都会调用?

    一个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>
            /* 1、如何改变promise的状态 
                (1)resolve(value) :如果当前的状态是pendding就会变成resolved
                (2)resolve(reason)) :如果当前的状态是pendding就会变成rejected
                (3)抛出异常:如果当前的状态是pendding就会变成rejected
    
                2.一个promise指定多个成功/失败的回调函数.都会调用?
                当promise状态改变时都会调用
    
            */
           let p = new Promise((resolve,reject) =>{
                //  resolve('成功')
                 reject('失败')
                 // throw '122'
    
            })
    
            // p.then((value) =>{console.log(value)}).catch(reason =>{
            //     console.log(reason);
            // })
          
    
            p.then(
                (value) =>{console.log(value)},
    
            (reason) =>{
                console.log('reason'+reason);
            })
    
    
    
            p.then(
                (value) =>{console.log(value)},
    
            (reason) =>{
                console.log('reason2'+reason);
            })
        </script>
        
    </body>
    </html>
    

      

  • 相关阅读:
    今日总结
    今日总结
    团队绩效1
    本周总结
    团队冲刺阶段10
    团队冲刺阶段9
    团队冲刺阶段8
    promise手写自定义封装异步任务回调的执行
    Vue中this.$options.data()和this.$data知多少?
    手写Promise自定义封装 then 函数
  • 原文地址:https://www.cnblogs.com/malong1992/p/14412150.html
Copyright © 2011-2022 走看看