title: jQuery variable scope? says undefined
body: <p>I have the following code:</p>
  
  <pre><code>function postToDrupal(contacts, source, owner) {
    (function ($) {
  
      var contact, name, email, entry;
      emails = {};
  
      for (var i = 0; i &lt; contacts.length; i++) {
        contact = contacts[i];
        emails[i]['name'] = contact.fullName();
        emails[i]['email'] = contact.selectedEmail();
      }
  
      $.post("/cloudsponge-post",emails,function(data) {
  
      });
    }(jQuery));
  }
  </code></pre>
  
  <p>I get the following error when I try and run it:</p>
  
  <pre><code>WARN: Attempt to invoke callback [afterSubmitContacts] failed: TypeError: Cannot set property 'name' of undefined
  </code></pre>
  
  <p>I'm not sure what the problem is- I'm quite new to JS and finding it a bit tricky. What's the reason it's broken, and how do I go about fixing it?</p>