以下に、jQuerydeferredを使用するサンプルコードがあります。私が理解できないように見えるのは、brushTeeth関数が拒否されたpromiseを返すのに、なぜ別の遅延であるcollectionResultsが常に解決されるのかということです。
一部のjQueryの遅延読み取りでは、$。whenで渡された関数がpromiseでない場合、それらはすぐに解決されますが、brushTeethは実際にはpromiseを返します。
私がここで間違っていることの手がかり?
ShowerModule = ( function($) {
function init(){
var result = $.Deferred();
var collectionResults = $.when(brushTeeth);
collectionResults.done(function(){
console.log("done");
})
collectionResults.fail(function(){
console.log("reject");
})
}
function brushTeeth() {
var result = $.Deferred();
result.reject('["bah"]');
return result.promise();
}
return {
init : init
}
}(jQuery));
ShowerModule.init();