一個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>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM