title: chaining promises with q.js
body: <p>I'm trying to understand how promise chaining works.  I'm using <a href="https://github.com/kriskowal/q">q.js</a>.  Here's what I'm playing with.</p>
  
  <pre><code>var Q = require("q"); // npm install q
  
  // the function Q(value) returns a fulfilled promise with the value... I think.
  Q(1).then(Q(2)).then(Q(3)).then(Q(4)).then(function(n) {
      console.log(n);
  });
  
  Q(1).then(function(n) {
      return Q(2);
  }).then(function(n) {
      return Q(3);
  }).then(function(n) {
      return Q(4);
  }).then(function(n) {
      console.log("done: " + n);
  });
  </code></pre>
  
  <p>My question basically boils down to why does the first one log <code>1</code> while the latter one logs what I would expect and basically logs 1 through 4.  I had hoped the first one would log <code>4</code> instead of <code>1</code>.</p>
  
  <p>I really just wanted to be able to have some methods that return promises and then chain them together in a waterfall like fashion - I guess I could use <a href="https://github.com/caolan/async">async</a> and waterfall, but just wanted to know if this could be achieved w/ promises.</p>