2
看起來好像then()
回調未觸發時Deferred
對象是reject
編輯。這是我的理解then()
是否Deferred
解決或拒絕應執行。jQuery.Deferred「then」callback given unexpected behavior
下面是一個例子(open in a jsFiddle console)
var doDfd = function(input){
var dfd = $.Deferred();
if(input == 'fail'){
dfd.reject();
}
else{
dfd.resolve();
}
return dfd.promise();
}
doDfd('fail')
.done(function(r){console.log('success')})
.fail(function(r){console.log('fail')})
.then(function(r){console.log('then logic')});