Providing Synchronous / Asynchronous Flexibility With jQuery.when

Javascript works asynchronously. But sometimes you need some synchronicity. Derick Bailey has a nice post about this:

http://lostechies.com/derickbailey/2012/03/27/providing-synchronous-asynchronous-flexibility-with-jquery-when/

Example

var that = this;

var templateRetrieved = this.getTemplate();

$.when(templateRetrieved).then(function(template){
   var html = that.renderTemplate(template, data);
   that.$el.html(html);

});