title: When to assign functions to variable, using jquery
body: <p>so I've been messing around with some Jquery Ajax promises/deffers etc... and i've come across something I don't completely understand, not strictly related to the Jquery Ajax. </p>
  
  <p>I have always declared and called functions like so:</p>
  
  <pre><code>function foo1() { //sets function
      alert('foo1');
  }
  
  foo1(); //calls function
  </code></pre>
  
  <p>But it seems the more I see different code a lot of people are declaring functions like the following, I just copied and pasted an example I saw so I would't miss anything:</p>
  
  <pre><code>var promise = $.ajax({
      url: "/myServerScript"
  });
  
  promise.done(myStopAnimationFunction);
  </code></pre>
  
  <p>I understand what the above does, just an example.</p>
  
  <p>The question is, is it better to assign functions to variables? What are the pros/cons, and in what situations is this way used?
  At what point in this code is the actual function called. Does</p>
  
  <pre><code>    promise.done(myStopAnimationFunction);
  </code></pre>
  
  <p>call both the ajax function, and then the callback, or just the callback?</p>
  
  <p>Thanks</p>