* async的使用:
* 添加在普通函数定义前面,让其成为一个异步函数。或者成为async函数。
* 1.async函数返回的是一个Promise对象。
* 2.async函数内部return的值,就是then函数中回调函数的参数。
* 3.async函数内部如果有错误,会执行catch函数,catch函数中的回调函数的参数就是抛出的错误信息。
*
function getMsg(){
return "donghu";
}
console.log(getMsg());
async function getMsgAsync(){
return "123";
}
getMsgAsync().then(msg=>{
console.log(msg);
});
console.log(getMsgAsync());
async function getMsg(){
throw "donghu";
}
getMsg().then(()=>{
console.log("msg");
}).catch(e=>{
console.log("catch函数被执行了");
console.log(e);
})