面试题答案
一键面试asyncOperation1()
.then(result1 => asyncOperation2(result1))
.then(result2 => asyncOperation3(result2))
.then(finalResult => {
console.log('所有操作成功,最终结果:', finalResult);
// 收尾操作
finalCleanup();
})
.catch(error => {
console.error('操作过程中出现错误:', error);
// 错误处理的收尾操作
errorCleanup();
})
.finally(() => {
console.log('统一的收尾操作');
});
function finalCleanup() {
// 成功时的收尾操作逻辑
}
function errorCleanup() {
// 错误时的收尾操作逻辑
}