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)
这样的东西。我看过 documentation ,但似乎找不到任何合适的东西。有没有比上述方法更好的方法来创建延迟对象之间的依赖关系?
最佳答案
因为我们能够register multiple callbacks sequentially now ,我个人觉得以这种方式设置依赖关系更清晰:
a = $.Deferred();
b = $.Deferred();
a.done(fncDoStuffForA);
b.done(fncDoStuffForB);
b.done(a.resolve)
b.resolve("Hey there!")
关于javascript - 在 jQuery 延迟对象中设置依赖关系的简写是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6868457/