1.async函数
async doubleAfter2seconds(num) {
console.log(num + 'kkk')
},
async mm() {
let n = await this.doubleAfter2seconds(2)
console.log(n)
}
2kkk
undefined
async函数没有返回值 默认返回 promise:{resolve}
await 等待的是promise执行成功的结果
2.
async doubleAfter2seconds(num) {
console.log(num + 'kkk')
},
async mm() {
let n = this.doubleAfter2seconds(2)
console.log(n)
}
2kkk
Promise:{resolve:undefined}
async函数没有返回值 没有await 相当于打印async函数的返回值
3.
async doubleAfter2seconds(num) {
console.log(num + 'kkk')
return 1
},
async mm() {
let n = this.doubleAfter2seconds(2)
console.log(n)
},
2kkk
Promise:{resolve:2}
async函数有返回值 没有await相当于打印的是async函数的返回值
4.
async doubleAfter2seconds(num) {
console.log(num + 'kkk')
return 1
},
async mm() {
let n = await this.doubleAfter2seconds(2)
console.log(n)
}
2kkk
1
async函数有返回值 返回的是promise:{<resolve<1>>} await 等待promise 执行后的结果 1