//async 用来修饰一个返回Promise对象的函数
async function myPromise(){
return new Promise((res,rej)=>{
//console.log(1);
res()
})
}
//async 用来修饰一个普通函数
async function normalFunc(){
return "normal function"
}
var pro=myPromise();
var nor=normalFunc()复制代码
function getSomething() {
return "something";
}
function testPromise() {
return Promise.resolve("hello Promise");
}
async function testAsync() {
return "hello async";
}
async function testNormal() {
const v1 = await getSomething(); //await用来修饰一个普通函数
const v2 = await testPromise(); //await用来修饰一个返回promise对象的函数
const v3 = await testAsync(); //await用来修饰一个经过async构成的异步函数
//上面的await这种写法等价于下面这种promise的写法
console.log(getSomething())
let vv=testPromise().then(res=>{
console.log(res)
testAsync().then(res=>{
console.log(res)
})
})
console.log(v1,v2,v3);
}
testNormal()复制代码
若有什么描述不合理之处,欢迎指出promise