let fn = new Promise((resolve, reject) => {
setTimeout(() => {
reject("ok");
}, 1000);
});
fn.then().catch(console.log); // 方式一
fn.then(console.log, console.log); // 方式二
let fn = new Promise((resolve, reject) => {
setTimeout(() => {
reject("ok");
}, 1000);
});
fn.then().catch(console.log); // 方式一
fn.then(console.log, console.log); // 方式二
基本没什么区别,只是catch还能捕获then里抛出的错误
fn.then(function(){
throw new Error('then error');
})
.catch(function(err){
console.log(err.message);
});
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
没区别,只是第一种链式调用的代码更好看。