xinhang

// 为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
    })
  );
};

// 把小程序函数变成promise函数
const promisify = (fn) => {
  return (options, ...params) => {
    return new Promise((resolve, reject) => {
      fn(Object.assign({}, options, {
        success: resolve,
        fail: reject
      }), ...params);
    });
  }
};

分类:

技术点:

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-12-16
  • 2021-09-06
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-09-21
  • 2021-08-24
  • 2022-12-23
相关资源
相似解决方案