姐妹篇
如果你自认熟悉 Promise,来猜一下这个代码的运行结果
要用猜的,别偷偷用浏览器运行
const Err = async () => {
throw new Error(42);
};
const Obj = {
async A (){
try {
return Err();
} catch {
console.log('A');
}
},
async B (){
try {
await Err();
} catch {
console.log('B');
}
},
async C (){
try {
Err();
} catch {
console.log('C');
}
},
};
( async () => {
for( const key in Obj )
{
try {
await Obj[key]();
} catch {
console.log('D');
}
}
} )();