Promise.prototype.finally实现

Promise.prototype.finally()

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实现)