模拟实现一个 Promise.finally

Promise.prototype.finally = function (callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then(() => { throw reason })
);
};

 

posted @ 2022-05-16 09:38  下一秒钟已经不同  阅读(52)  评论(0编辑  收藏  举报