小程序 Promise的finally

432 阅读1分钟

ios小程序不支持Promisefinally方法,我们要做的是给Promise扩展finally

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