title: avoiding nested callbacks with promises
body: <p>I'm still new to using Promise APIs and I'm struggling how to avoid deeply nested Promise chains, which as far as I understand, are one of the benefits to using Promises.  Using the following pseudo code as an example, how do you avoid nesting Promises when the subsequent ones rely on the context of prior ones?</p>
  
  <pre><code>function loadDependency1() {
      // return a promsise to load the first dependency
  }
  
  function loadDependency2(dependency1) {
      // return a promise to load the second dependency, which relies on the first dependency
  }
  
  function loadDependency3(dependency2) {
      // return a promise to load the third dependency, which relies on the second dependency
  }
  
  function doWork(dependency1, dependency2, dependency3) {
      // finally have all the things necessary to do work
  }
  
  // load all the dependencies and eventually doWork
  loadDependency1().then(function(dependency1) {
      return loadDependency2(dependency1).then(function(dependency2) {
          return loadDependency3(dependency2).then(function(dependency3) {
              doWork(dependency1, dependency2, dependency3);
          });
      });
  });
  </code></pre>