title: how to solve 'this' problems with node libraries like async and request
body: <p>I've written a node script that gets some data by requesting REST API data (using the library request). It consists of a couple of functions like so:</p>
  
  <pre><code>var data = { /* object to store all data */ },
  function getKloutData() {
    request(url, function() { /* store data */}
  }
  // and a function for twitter data
  </code></pre>
  
  <p>Because I want to do some stuff after fetching all the I used the library async to run all the fetch functions like so:</p>
  
  <pre><code>async.parallel([ getTwitterData, getKloutData ], function() {
      console.log('done');
  });
  </code></pre>
  
  <p>This all works fine, however I wanted to put everything inside a object pattern so I could fetch multiple accounts at the same time:</p>
  
  <pre><code>function Fetcher(name) { 
      this.userID = ''
      this.user = { /* data */ }
      this.init();
  }
  Fetcher.prototype.init = function() {
      async.parallel([ this.getTwitterData, this.getKloutData ], function() {
          console.log('done');
      });
  }
  Fetcher.prototype.getKloutData = function(callback) {
      request(url, function () { /* store data */ });
  };
  </code></pre>
  
  <p>This doesn't work because async and request change the this context. The only way I could get around it is by binding everything I pass through async and request:</p>
  
  <pre><code>Fetcher.prototype.init = function() {
      async.parallel([ this.getTwitterData.bind(this), this.getKloutData.bind(this) ], function() {
          console.log('done');
      });
  }
  Fetcher.prototype.getKloutData = function(callback) {
      function saveData() {
          /* store data */
      }
  
  
      request(url, saveData.bind(this);
  };
  </code></pre>
  
  <p>Am I doing something basic wrong or something? I think reverting to the script and forking it to child_processes creates to much overhead.</p>