jQuery 1.5: Why is Deferred object calling .done() in UNRESOLVED state? -
i've created test page mimics problem getting on actual page.
as can see in dosomething2(), dfd object deliberately never resolved. however, when run following code, .done() in dosomething() fires. inspecting console, see dfd.isresolved() false right before .done() runs.
any insights? appreciated
<!doctype html> <html> <head> <title>testing page</title> <script src="jquery-git-02092011.js" type="text/javascript"></script> </head> <body> <div id="test"> <div ></div> <div ></div> </div> <script> function dosomething() { $('#test div').each(function(){ $(this).append($('<div></div>').load('http://www.google.com',function(){ dosomething2().done(console.log('dosomething2 complete')); })) }); } function dosomething2() { var dfd = $.deferred(); console.log(dfd.isresolved()); return dfd; } $(document).ready(function() { dosomething(); }); </script> </body> </html> edit: understand function accomplishes nothing. i've made example replicate problem. understand fetching 'google.com' against sop. i've created example replicate problem. developing web app meant run locally 1 html file. in case, sop not strictly adhered to, should ok @ least test.
edit:i've created jsfiddle test behavior: http://jsfiddle.net/sgwpv/2/
your problem passing in statement .done rather function
see live example
internally, .done takes list of functions , pushes them callback array so
callbacks.push(elem);
you pass in statement elem , get
callbacks.push(alert("foo"));
your pushing return value of statement (in case undefined) callback array rather function.
Comments
Post a Comment