Javascript: Async chains with jQuery.Deferred

Oscar Brito

Very useful utility to chain async events on javascript.


function timeout(x) { 
       var dfd = jQuery.Deferred(); 
       setTimeout(function() { 
       }, x); 
       return dfd.promise(); 

jQuery.when(timeout(800), timeout(500)).done(function() {});

The timeout function will call resolve and done function is invoked! It's more semantic and respect a common API (

Visit for more informations, contacts and news about Web Development.
See other blog posts at

Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.

Feel free to contact divhide.