1. 程式人生 > 其它 >2-當Promise物件成功或失敗時能否執行多個回撥

2-當Promise物件成功或失敗時能否執行多個回撥

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <script> let p = new Promise((resolve, reject) => { // resolve("Ok"); // 不改變狀態,初始值為pending時指定的所有回撥都不會執行 });
// 指定回撥-1 p.then( (value) => { console.log(value); }, (reason) => { //函式體 } );
// 指定回撥-2 p.then( (value) => { alert(value); }, (reason) => { //函式體 } );
/** * 當Promise物件成功或失敗時指定的對應的所有的回撥函式都會執行 * */ </script> </body> </html>