我正在尝试扩展这两个 promise :
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());
});
});
并收到此错误:
“Constructor Promise 需要'new'”
我正在使用"new",那么它想从我这里得到什么?
最佳答案
这似乎是答案
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/