// function timeout(){
// return new Promise((resolve,reject)=>{
// setTimeout(()=>{
// reject("fail")
// // resolve("success")
// },1000)
// })
// }
// async function foo(){ //async返回一个promise对象
// const s = await timeout();//await:只有等到一个是成功状态的promise才会执行后面的代码;返回resolve或reject里面参数
// console.log(s)
// console.log(2)
// }
// async function foo(){
// return await timeout(); //返回 将await返回的结果 包装成的promise对象
// }
// foo().then(res=>{
// console.log(res);
// }).catch(err=>{
// console.log(err)
// })
async await
最新推荐文章于 2023-06-06 14:26:14 发布