title: JQuery deferred.done executes predefined function instantly, but not function declared inside
body: <p>My problem is a weird one, as described in the title. Here's the code:</p>
  
  <p>Case 1:</p>
  
  <pre><code>    var first = $.ajax({ // about 500ms request
          url: myUrl
          success: function() { console.log(1); }
      });
  
      var second = $.ajax({ // about 200 ms request
          url: myUrl
          success: function() { console.log(2); }
      });
  
  
      $.when(first, second).done(function() { console.log(3); });
  </code></pre>
  
  <p>Logs 2, 1, 3. All good, just what I wanted.</p>
  
  <p>Case 2:</p>
  
  <pre><code>    var first = $.ajax({ // about 500ms request
          url: myUrl
          success: function() { console.log(1); }
      });
  
      var second = $.ajax({ // about 200 ms request
          url: myUrl
          success: function() { console.log(2); }
      });
  
      function logthree() {
          console.log(3);
      }
  
  
      $.when(first, second).done(logthree());
  </code></pre>
  
  <p>Logs 3, 2, 1, which is a problem. The logthree() function should only execute once first and second resolve.</p>
  
  <p>Why does this happen? How can I use Case 2 without any problems?</p>
  
  <p>Note: same thing happens if first and second are functions and they return an $.ajax.</p>
  
  <p>Note: same thing happens if first and second are both $.get.</p>