title: Promise nesting vs chaining style
body: <p>New to promises; consider the case where there is <code>promiseA()</code> and <code>promiseB(a)</code> which depends on the first result, and I want to collect results from both and perform a third action <code>doSomething(a, b)</code>:</p>
  
  <p><strong>Style A (closure/nesting)</strong></p>
  
  <pre><code>promiseA().then(function (resultA) {
    return (promiseB(resultA).then(function (resultB) {
      doSomething(resultA, resultB);
    }));
  });
  </code></pre>
  
  <p><strong>Style B (return value/chaining)</strong></p>
  
  <pre><code>promiseA().then(function (resultA) {
    return Promise.all([resultA, promiseB(resultA)]);
  }).spread(function (resultA, resultB) {
    doSomething(resultA, resultB);
  });
  </code></pre>
  
  <p>As far as I can tell, these are equivalent:</p>
  
  <ul>
  <li>Same sequencing constraint between <code>promiseA</code> and <code>promiseB</code></li>
  <li>Final promise returns <code>undefined</code></li>
  <li>Final promise is rejected if <code>promiseA</code> or <code>promiseB</code> are rejected, or <code>doSomething</code> throws.</li>
  </ul>
  
  <p>As a matter of style, Style B reduces indentation (pyramid of doom).</p>
  
  <p>However, Style B is more difficult to refactor. If I need to introduce an intermediate <code>promiseA2(a)</code> and <code>doSomething(a, a2, b)</code>, I need to modify 3 lines (<code>Promise.all</code>, <code>spread</code>, <code>doSomething</code>), which can lead to mistakes (accidental swapping etc), while with Style A I only to modify 1 line (<code>doSomething</code>) and the variable name makes it clear which result it is. In large projects, this may be significant.</p>
  
  <p>Are there other non-functional trade-offs between the two styles? More/less memory allocation in one vs the other? More/fewer turns around the event loop? Better/worse stack traces on exceptions?</p>