title: How to pass to when array of deferred with their own callbacks
body: <p>Is it possible to pass to <code>$.when</code> array of deferred with their own callbacks? So I want each callback to be called after all deferred are resolved in order they are passed to <code>$.when</code>.</p>
  
  <p>For instance in example below callback is called immediately after appropriate deferred is resolved and only general callback in <code>$.when</code> is called after all deferred is done</p>
  
  <pre><code>var d1 = $.Deferred();
  var d2 = $.Deferred();
  
  d1.done(function(result){alert('d1 is done');});
  d2.done(function(result){alert('d2 is done');});
  
  $.when(d1, d2).done(function(result){
  alert('here only general callback is called');
  });
  
  d1.resolve();
  
  setTimeout(function(){d2.resolve();}, 3000);
  </code></pre>
  
  <p><strong>EDIT:</strong>
   Where I need to use it. Let's say I have several functions:</p>
  
  <pre><code>function SomeFunction1(){
  var d = $.Deferred();
  
  //if I define callback here it will call immediately after resolve
  //d.done(function(result){
  //// do something with result
  //});
  
  //$.ajax() or $.get() or $('#someID').load() or whatever else or just d.resolve
  d.resolve('someData1');
  
  return d.promise();
  }
  
  function SomeFunction2(){
  var d = $.Deferred();
  
  //if I define callback here it will call immediately after resolve
  //d.done(function(result){
  //// do something with result
  //});
  
  //$.ajax() or $.get() or $('#someID').load() or whatever else or just d.resolve
  d.resolve('someData2');
  
  return d.promise();
  }
  
  ...
  
  function SomeFunctionN(){
  var d = $.Deferred();
  
  //if I define callback here it will call immediately after resolve
  //d.done(function(result){
  //// do something with result
  //});
  
  //$.ajax() or $.get() or $('#someID').load() or whatever else or just d.resolve
  d.resolve('someDataN');
  
  return d.promise();
  }
  </code></pre>
  
  <p>Then in some case I need to call only one of these functions, in some other case two of them, in third situation all of them:</p>
  
  <pre><code>1: $.when(SomeFunction1()).done(function(result){
  //callback defined inside SomeFunction1
  });
  
  2: $.when(SomeFunction1(), SomeFunction2()).done(function(result){
  //callbacks defined inside SomeFunction1 and SomeFunction2
  });
  
  3: $.when(SomeFunction1(), SomeFunction2(), ... , SomeFunctionN()).done(function(result){
  //callbacks defined inside SomeFunction1, ... , SomeFunctionN
  });
  </code></pre>
  
  <p>And callbacks on success and on error should be defined inside these functions but execute only AFTER all of called functions return result.</p>
  
  <p>Is it possible?</p>