【发布时间】:2015-04-28 07:34:13
【问题描述】:
我正在尝试使用生成器创建一个承诺包装器,以便我可以这样做:
var asyncResult = PromiseWrapper( $.ajax( ... ) );
到目前为止,我一直在尝试:
function PromiseWrapper(promise){
return function *wrapper(promise){
promise.then(function(result){
yield result;
}, function(err){
throw err;
});
}(promise).next().value
}
但这失败了,因为不允许在法线内屈服。 有什么解决方法吗?谢谢 :D
ps:我正在使用 babel 将代码从 es6 翻译成 es5
【问题讨论】:
-
yielding inside promise is not allowed- 应该是yielding inside a normal function is not allowed -
@thefourtheye 没错,我现在就编辑它
标签: javascript generator ecmascript-6 es6-promise