title: raising jquery deferred.then() once all deferred objects have been resolved
body: <p>i have two javascript functions, <code>save()</code> and <code>saveAll()</code>, set up as below:</p>
  
  <pre><code>function save(data) {
      return $.post('/save', data);
  }
  
  function saveAll(callback) {
      var dataArray = [];
      $.each(dataArray, function() {
          save(this);
      });
      callback();
  }
  </code></pre>
  
  <p>i'm interested in modifying <code>saveAll()</code> so that it leverages jquery deferred objects, and raises the <code>callback</code> function once all <code>save()</code> operations have completed.  however, i'm unsure of the exact syntax... specifically with relation to the $.each() inside of the $.when().  would it be something like this?</p>
  
  <pre><code>function saveAll(callback) {
      var dataArray = [];
      $.when(
          $.each(dataArray, function() {
              return save(this);
          })
      ).then(callback);
  }
  </code></pre>