在 jQuery 延迟对象中设置依赖关系的简写是什么?
jQuery 延迟对象是否有任何设置依赖关系的简写,即“当我完成时,那件事也完成了?”下面的内容感觉很麻烦:
a = new jQuery.Deferred();
b = new jQuery.Deferred();
a.done(function(result){alert(result);});
b.done(function(result){a.resolve(result);}); // this line doesn't feel right
b.resolve("Hey there!")
我喜欢像 b.alsoResolves(a)
这样的东西。我查看了 文档,但似乎找不到任何合适的内容。有没有比上面更好的方法来创建延迟对象之间的依赖关系?
Do jQuery deferred objects have any shorthand to set up dependencies, i.e. "when I'm done, that thing is done as well?" The below feels cumbersome:
a = new jQuery.Deferred();
b = new jQuery.Deferred();
a.done(function(result){alert(result);});
b.done(function(result){a.resolve(result);}); // this line doesn't feel right
b.resolve("Hey there!")
I'd love something like b.alsoResolves(a)
. I've looked at the documentation, but can't seem to find anything appropriate. Is there any better way to created dependencies between deferred objects than the one above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我们现在能够按顺序注册多个回调,我个人发现以这种方式设置依赖关系更干净:
http://jsfiddle.net/rkw79/cdkG3/
Since we are able to register multiple callbacks sequentially now, I personally find it cleaner to set dependencies this way:
http://jsfiddle.net/rkw79/cdkG3/