Mar 19, 2011

the when method

In jQuery 1.5, there is a "when" method.

function when(objects) {}

//we can call with like
jQuery.when(object1, object2, object3, ..).then(done, fail);


The semantics of the function is when ALL the objects'(object1, object2, ..) value is realized, then call the done function with all the realized value, when one of them fail, call the fail function. These objects can be a "realized" value or a promise (promising value). If all the value are already "realized" initially, the done function will be called synchronously.