运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Promise Object</h1> <h2>The Promise.allSettled() Method</h2> <p id="demo"></p> <script> // Create a Promise const myPromise1 = new Promise((resolve, reject) => { setTimeout(resolve, 200, "King"); }); // Create another Promise const myPromise2 = new Promise((resolve, reject) => { setTimeout(resolve, 100, "Queen"); }); // Settle All Promise.allSettled([myPromise1, myPromise2]).then((results) => results.forEach((x) => myDisplay(x.status)), ); // Funtion to run when a Promise is settled: function myDisplay(some) { document.getElementById("demo").innerHTML += some; } </script> </body> </html>