运行 ❯
获取您自己的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Promise Object</h1> <h2>The Promise.any() 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"); }); // Run when Any promise fulfills Promise.any([myPromise1, myPromise2]).then((x) => { myDisplay(x); }); // Funtion to run when a Promise is settled: function myDisplay(some) { document.getElementById("demo").innerHTML += some; } </script> </body> </html>