title: What does $.when.apply($, someArray) do?
body: <p>I'm <a href="https://flaviocopes.com/blog/deferreds-and-promises-in-javascript">reading about Deferreds and Promises</a> and keep coming across <code>$.when.apply($, someArray)</code>.  I'm a little unclear on what this does exactly, looking for an explanation that <strong>one line</strong> works exactly (not the entire code snippet).  Here's some context: </p>
  
  <pre><code>var data = [1,2,3,4]; // the ids coming back from serviceA
  var processItemsDeferred = [];
  
  for(var i = 0; i &lt; data.length; i++){
    processItemsDeferred.push(processItem(data[i]));
  }
  
  $.when.apply($, processItemsDeferred).then(everythingDone); 
  
  function processItem(data) {
    var dfd = $.Deferred();
    console.log('called processItem');
  
    //in the real world, this would probably make an AJAX call.
    setTimeout(function() { dfd.resolve() }, 2000);    
  
    return dfd.promise();
  }
  
  function everythingDone(){
    console.log('processed all items');
  }
  </code></pre>