promise.finally.js 250 B

12345678
  1. // promise finally 实现
  2. Promise.prototype.finally = function (callback) {
  3. let P = this.constructor;
  4. return this.then(
  5. value => P.resolve(callback()).then(() => value),
  6. reason => P.resolve(callback()).then(() => { throw reason })
  7. );
  8. };