Javascript works asynchronously. But sometimes you need some synchronicity. Derick Bailey has a nice post about this:
Example
var that = this; var templateRetrieved = this.getTemplate(); $.when(templateRetrieved).then(function(template){ var html = that.renderTemplate(template, data); that.$el.html(html); });