Sunny-117/js-challenges

5. 实现 Promise.prototype.catch

Sunny-117 opened this issue · 1 comments

 /**
   * 本质就是then,只是少传了一个onFulfilled
   * 所以仅处理失败的场景
   * @param {*} onRejected
   */
Promise.prototype.catch = function(onRejected) {
    return this.then(null, onRejected);
}
cscty commented

Promise.prototype.catch = function (fn) {
this.then(undefined, (err) => {
fn(err);
});
};