Promise.prototype.finally = function(onFinally) {
return this.then(
/* onFulfilled */
res => Promise.resolve(onFinally()).then(() => res),
/* onRejected */
err => Promise.resolve(onFinally()).then(() => { throw err; })
);
};
Promise.prototype.finally = function(onFinally) {
return this.then(
/* onFulfilled */
res => Promise.resolve(onFinally()).then(() => res),
/* onRejected */
err => Promise.resolve(onFinally()).then(() => { throw err; })
);
};
本文标题:Promise.prototype.finally实现
本文链接:https://www.haomeiwen.com/subject/fpiqectx.html
网友评论