5. 实现 Promise.prototype.catch
Sunny-117 opened this issue · comments
/**
* 本质就是then,只是少传了一个onFulfilled
* 所以仅处理失败的场景
* @param {*} onRejected
*/
Promise.prototype.catch = function(onRejected) {
return this.then(null, onRejected);
}
Promise.prototype.catch = function (fn) {
this.then(undefined, (err) => {
fn(err);
});
};