javascript await正确写法 (支持微信小程序)
ps
1 返回异步的前面都加个关键字 async
2 await必须卸载async里面 因为是异步里面的同步
async function doubleAfter2seconds(num) { return new Promise((resolve, reject) => { setTimeout(() => { resolve('2秒后触发'); }, 2000); }) } async function doubleAfter1seconds(num) { return new Promise((resolve, reject) => { setTimeout(() => { resolve('1秒后触发') }, 1000); }) } async function ssd(){ var result = await doubleAfter2seconds(30); console.log(result); var result = await doubleAfter1seconds(30); console.log(result); }
ssd();
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18765.html