when a function returns a promise, I can call some other function after the first one did it's work:
do_stuff().then(function(){
  alert('yoooo');
});
and do_stuff() looks like this:
function do_stuff(){
  if(!got_the_data){
    var d = $.Deferred();
    $.ajax({
      success: function(html){
        $('#box').append(html);
        $('#box').addClass('visible');
        $('#box').on('transitionend webkitTransitionEnd', function(){
          got_the_data = true;
          d.resolve();
        });
      }
    });
    return d.promise();
  }else{
    // got the data, what now?
  }
}
but what do I return if I already did the ajax request (result is cached) and I don't have to wait for anything? I can't return d.resolve() because the function that was attached to then() won't fire :/
and I can't return d.promise because I have to resolve the "d" somewhere
 
     
    