I'm trying to extend these two promises:
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());
});
});
and am receiving this error:
"Constructor Promise requires 'new'"
I'm using 'new', so what does it want from me?
This seems to be the answer
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());
});
it('using `class X extends Promise{}` is possible', function() {
class MyPromise extends Promise {}
const promise = new MyPromise((resolve, reject) => {})
promise
.then(() => done())
.catch(e => done(new Error('Expected to resolve, but failed with: ' + e)));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.