I'm still trying to wrap my head using jQuery Deferred objects and scratching my head on one specific issue. In the following code, I first tried linking deferred.then() , but it never worked. All three functions are performed immediately. Only after my employee pointed me to the pipe function did everything fall into place. The question is why pipe() works, but not then() ?
var otherDefer = function(msg){return function(){return testDefer(msg)}}; var there = otherDefer("there,"); var guy = otherDefer("guy."); function testDefer(msg) { var deferred = $.Deferred(); pretendAjaxCall( function() { $('<li>'+msg+'</li>').appendTo('#msgOut'); deferred.resolve(); }); return deferred.promise(); } function pretendAjaxCall(callback) { setTimeout(callback,1500); } $.when(testDefer("Hi")).pipe(there).then(guy);β
I also tried return deferred instead of return deferred.promise() when using when().then().then() .
jsFiddle for the code above: http://jsfiddle.net/eterpstra/yGu2d/
eterps
source share