await和async
async
async将函数变为异步函数
await
await相当于异步等待,异步函数内如果有await即表示等待这一句执行完毕之后再执行后面的代码
await和async只发生在其函数作用域内,不会阻塞js进程
function aa () { return new promise((resolve, reject) => { let nums = parseInt(Math.random*6+1); setTimeout(() => { resolve(nums); }, 2000) }) } async function bb () { let n = await aa(); console.log("摇到数字"+n); } bb();
标签:aa,function,函数,异步,await,async From: https://www.cnblogs.com/wyl-k/p/17747184.html