If I want to have synchronous and asynchronous functions execute in a particular order I could use jQuery promise but it doesn\'t seem to work the way I\'d expect it to work
jQuery < 1.8 is fine WRT chaining, you just use .pipe
instead of .then
. 1.8 simply changed .then
to be .pipe
.
Sidenote: When you use it without the array, you don't have to start with a promise. $.when({}).then(a).then(b)
will do the trick just fine. You only need to make sure you don't put a
inside the when
.
For jQuery prior to 1.8, this is a problem, but for new versions of jQuery, this is not a problem anymore:
function test(){
var d = jQuery.Deferred(),
p=d.promise();
//You can chain jQuery promises using .then
p.then(a).then(b).then(c);
d.resolve();
}
test();
DEMO
Below is the demo of jQuery 1.7.2
DEMO