通过ES6 Katas工作,扩展承诺
Working through ES6 Katas, extending 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());
});
});
和我收到这个错误:
"Constructor Promise require '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());
});
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)));
});
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 我的职位回报太快了,如何做出承诺
- 打破承诺链的好方法是什么
- 扩展移相器按钮类不工作
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 从函数返回角度承诺
- TableExport jquery插件:文件名和扩展名问题
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 扩展SVGTextElement时出现Typescript Uncaught TypeError
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 传播承诺并在新对象中扩展
- 扩展函数(如 .all()、.final() 等是否有承诺标准?
- 用额外数据扩展承诺
- 正确的方式来解决一个对象将被扩展后,解决不同的承诺
- 通过ES6 Katas工作,扩展承诺
- 扩展ES6承诺,将回调转换为Deferred模式
- 创建带有chrome扩展要求的蓝鸟承诺时出错