JavaScript Async 异步请求Await 语法函数前的关键字 await 使函数等待 promise:let value = await promise; await 关键字只能在 async 函数中使用。实例让我们来学习如何使用它。async function getFile() { let promise = new Promise(function(resolve, reject) { let req = new XMLHttpRequest(); req.open(...
duration ); duration = audio.duration ; }); } function callBackFun3(leng){ alert('222 leng='+leng) ; } var src = "https://www.w3schools.com/tags/horse.mp3" ; async function aaa(){ alert(111); await getAudioUrlDuration(src, callBackFun3 ) ; alert( '333 duration='+duration )...
document.getElementById("demo").innerHTML=awaitmyPromise; } myDisplay(); Try it Yourself » The two arguments (resolve and reject) are pre-defined by JavaScript. We will not create them, but call one of them when the executor function is ready. ...