title: Javascript ES6 promise inside class function
body: <p>After having read pages and pages about promises, I still cannot figure out the right way to return a promise (ES6 spec) inside a class function.</p>
  
  <p>Here are the various options I've tried.
  <code>utils.getMyPhotos()</code> returns a promise.</p>
  
  <blockquote>
    <p>1) Return the promise AND it's values</p>
  </blockquote>
  
  <pre><code>profilePictures(){
      return utils.getMyPhotos().then(function(result){
              var photosArray = result;
              photosArray.forEach(function(element) {
                  this._list.push(new Picture(
                      element.src,
                      element.caption
                      ));
              }, this);
              return this._list;
  
          },function(error){
              console.log(error);
              return error;
          });
          }
  </code></pre>
  
  <blockquote>
    <p>2) Only return the promise' values</p>
  </blockquote>
  
  <pre><code> profilePictures(){
          utils.getMyPhotos().then(function(result){
              var photosArray = result;
              photosArray.forEach(function(element) {
                  this._list.push(new Picture(
                      element.src,
                      element.caption
                      ));
              }, this);
              return this._list;
  
          },function(error){
              console.log(error);
              return error;
          });
          }
  </code></pre>
  
  <blockquote>
    <p>3)Create a new Promise and return it</p>
  </blockquote>
  
  <pre><code> profilePictures(){
   return new Promise(function(fulfill,reject){
   utils.getMyPhotos().then(function(result){
              var photosArray = result;
              photosArray.forEach(function(element) {
                  this._list.push(new Picture(
                      element.src,
                      element.caption
                      ));
              }, this);
              fulfill(this._list);
  
          },function(error){
              console.log(error);
              reject(error);
          });
          }
   }
  </code></pre>
  
  <p>I try to use the above function as following :</p>
  
  <pre><code>pictures.profilePictures().then(function(result){
          console.log("all good");
          console.dump(result);
      },function(error){
          console.log("errors encountered");
          console.log(error);
      });
  </code></pre>
  
  <p>Hoever in the CLI I only see "errors encountered" followed by an empty <code>error</code> object.</p>
  
  <p>What am I doing wrong?</p>