title: Nodejs calling function from within a function
body: <p>I have 3 methods</p>
  
  <pre><code>exports.getImageById = function (resultFn, id) {
   ...
  }
  
  exports.getCollectionById = function (resultFn, id) {
  }
  </code></pre>
  
  <p>in the third method I want to call both methods</p>
  
  <pre><code>exports.getCollectionImages = function (resultFn, collectionId) {
  
  var arr = new Array();
  
  this.getCollectionById(   // fine, 1st call
      function (result) {
          var images = result.image;
          for (i = 0; i &lt; images.length; i++) {
              this.getImageById(function (result1) {   // error, 2nd call
                      arr[i] = result1;
                  }, images[i]
              );
  
           }
      }
      , collectionId
  );
  
  resultFn(arr);
  }
  </code></pre>
  
  <p>I can call first function <code>this.getCollectionById</code> but it fails to call <code>this.getImageById</code>, it says undefined function, whats the reason for that?</p>