我知道除了语法之外,Deferred.done(a).fail(b)与Deferred.then(a,b)是完全相同的,但我想知道是否有一种首选的语法方式。
我为什么要用一个而不是另一个?有最好的做法吗?我现在能提出的唯一论点是,如果我在.done(a).fail(b)的情况下遇到了失败函数'b‘,我马上就知道,当我看到fail(b)时,它是一个失败函数,而当我在当时(a,b)的情况下看到b时,我没有看到这个函数。还有其他的争论吗?
发布于 2013-04-09 11:43:30
.done(a).fail(b)是一种更语义的方法,所以我支持它。
发布于 2013-07-17 16:45:24
当您有多个任务要完成或失败时,请使用Deferred.then(a,b)。
例如:
$.when(task1)
.then(task2, task1Failure)
.then(task3, task2Failure)
.fail(task3Failure);或
$.when(task1)
.then(task2, task1Failure)
.then(task3, task2Failure)
.then(task3SuccessMeaningAllSuccess, task3Failure);https://stackoverflow.com/questions/11841979
复制相似问题