function fn(){
return new Promise((resolve)=>{
setTimeout(()=>{
resolve('hi')
},1000)
})
}
(async function(){
let res1 =await fn();
console.log('第一步')
let res2 = await fn();
console.log(res2+'第二步')
let res3 = await fn();
console.log(res3+'第三步')
console.log('================')
})()
async function bb(){
let res1 =await fn();
console.log('第一步')
let res2 = await fn();
console.log(res2+'第二步')
let res3 = await fn();
console.log(res3+'第三步')
console.log('================')
}
// bb()
let obj = {
say:async function(){
let result = await fn()
console.log('say:'+result)
},
eat: async ()=>{
let result = await fn();
console.log('eat:'+result)
}
}
// awaint只能在async函数中执行
// await fn()
let aa = async function(){
await obj.eat();
await obj.say()
console.log('```````````````````')
}
aa()
网友评论