【发布时间】:2022-01-05 11:55:22
【问题描述】:
假设我有一个 Promise 并像这样捕获错误:
fetch().then(data => {
console.log(data);
}).catch(console.error);
这是一个有效的代码吗?我见过有人这样做,但我不明白 catch(console.error) 是如何工作的。
【问题讨论】:
-
为什么它不起作用?请注意如何简化为
fetch().then(console.log).catch(console.error);或只是fetch().then(console.log, console.error);
标签: javascript node.js promise