Skip to content

【JS】Promise.prototype.finally polyfill #55

@zh-rocco

Description

@zh-rocco

起因

Promise.prototype.finally 在 EDGE 浏览器中报错

解决

!(function() {
  Promise.prototype.finally =
    Promise.prototype.finally ||
    {
      finally(fn) {
        const onFinally = (cb) => Promise.resolve(fn()).then(cb);
        return this.then(
          (result) => onFinally(() => result),
          (reason) =>
            onFinally(() => {
              throw reason;
            }),
        );
      },
    }.finally;
})();

参考

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions