我正在尝试扩展以下两个承诺:

   it('using `class X extends Promise{}` is possible', function() {
  class MyPromise extends Promise {
    constructor()
    {
      super();
    }
  };
  const mypromise = new MyPromise((resolve) => resolve());

  promise
    .then(() => done())
    .catch(e => done(new Error('Expected to resolve, but failed with: ' + e)));
});

it('must call `super()` in the constructor if it wants to inherit/specialize the behavior', function() {
  class ResolvingPromise extends Promise {
    constructor() {
    super();
    }}

  return new ResolvingPromise((resolve) => resolve());
});

});


并收到此错误:

“建设者的承诺要求'新'”

我正在使用“新”,那么它要我做什么?

最佳答案

这似乎是答案

it('must call `super()` in the constructor if it wants to inherit/specialize the behavior', function() {
      class ResolvingPromise extends Promise {
        constructor(resolve) {
          super(resolve);
        }
      }

      return new ResolvingPromise((resolve) => resolve());
    });

关于javascript - 通过ES6 Katas开展工作,扩大 promise ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40404028/

10-11 06:08