function test(i) {
function test(i) {
$.Deferred();
if(i%2 == 0) {
console.log("resolve " i);
console.log("failure " i);
dfd.reject();
}
return dfd.promise
return dfd.promise
return dfd.promise(); > var dfd = $.Deferred();
var remain = 10;
for(var i=0;i for(var i=0;i 🎜> if(!(--remain)) {
}).fail(function() {
if(!(--remain)) {
dfd.resolve();
turn dfd.promise();
}
call().done(function() {
console.log("all finished");});
輸出結果:
複製程式碼
程式碼如下:resolve 0 test.js:4resolve 2 test.js:4
failure 3 test.js:7
resolve 4 test.js:4
failure 5 test.js:7
resolve 6 test.js:4
failure 7 test.js:7
resolve 8 test.js:4
failure 9 test.js:7
all finished