jQuery Deferred对象是否有任何简写来设置依赖关系,IE“当我完成时,那件事也完成了?”下面感觉很麻烦:
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)
之类的东西。我看过documentation,但似乎找不到合适的东西。是否有更好的方法来创建延迟对象之间的依赖关系?
答案 0 :(得分:1)
由于我们能够register multiple callbacks sequentially now,我个人认为以这种方式设置依赖关系更加清晰:
a = $.Deferred();
b = $.Deferred();
a.done(fncDoStuffForA);
b.done(fncDoStuffForB);
b.done(a.resolve)
b.resolve("Hey there!")