title: Using jQuery.when with array of deferred objects causes weird happenings with local variables
body: <p>Let's say I have a site which saves phone numbers via an HTTP call to a service and the service returns the new id of the telephone number entry for binding to the telephone number on the page.</p>
  
  <p>The telephones, in this case, are stored in an array called 'telephones' and datacontext.telephones.updateData sends the telephone to the server inside a $.Deferred([service call logic]).promise();</p>
  
  <pre><code>uploadTelephones = function (deffered) {
                  for (var i = 0; i &lt; telephones.length; i++){
                          deffered.push(datacontext.telephones.updateData(telephones[i], {
                              success: function (response) {
                                  telephones[i].telephoneId = response;                                    
                              },
                              error: function () {
                                  logger.error('Stuff errored');
                              }
                          }));                            
                   }
              }
  </code></pre>
  
  <p>Now if I call:</p>
  
  <pre><code>function(){
      var deferreds = [];
      uploadTelephones(deferreds);
      $.when.apply($, deferreds)
                      .then(function () {
                          editing(false);
                          complete();
                      },
                      function () {
                          complete();
                      });
  }
  </code></pre>
  
  <p>A weird thing happens. All the telephones are sent back to the service and are saved. When the 'success' callback in uploadTelephones method is called with the new id as 'response', no matter which telephone the query relates to, the value of i is always telephones.length+1 and the line</p>
  
  <pre><code>telephones[i].telephoneId = response; 
  </code></pre>
  
  <p>throws an error because telephones[i] does not exist.</p>
  
  <p>Can anyone tell me how to keep the individual values of i in the success callback?</p>