async/await demo
1235 ワード
html>
Document
async function promiseClick(){//
const p0=await f0()
const p1=await f1(p0)
const p2=await f2(p1)
console.log(p2);
}
function f0(){
return new Promise((resolve,reject)=>{
setTimeout(_=>{
return resolve({name:' '})//
},2000)
})
}
function f1(data){
return new Promise((resolve,reject)=>{
setTimeout(_=>{
data.age=222
return resolve(data)//
},2000)
})
}
function f2(data){
return new Promise((resolve,reject)=>{
setTimeout(_=>{
data.love=33
return resolve(data)
},2000)
})
}
let f3=new Promise((resolve,reject)=>{
setTimeout(_=>{
return resolve(' ')
},2000)
})
let f4= new Promise((resolve,reject)=>{
setTimeout(_=>{
return resolve('heheh')
},1000)
})