title: Q promises - How does scope work?
body: <p>How does the scope of the Q promises work? As far as I know the callback of the "then" is called by window, like a setTimeout.</p>
  
  <p>In this example (just an example to understand how it works):</p>
  
  <pre><code>var getFileText = function() {
      var deferred = Q.defer();
      Server.readFile("foo.txt", "utf-8", function (error, text) {
          if (error) {
              deferred.reject(new Error(error));
          } else {
              deferred.resolve(text);
          }
      });
      return deferred.promise;
  };
  
  var Foo =  function () {
      getFileText().then(this.showFile);
  };
  
  Foo.prototype.showFile = function(text) {
      this.text = text;
      console.log(text);
  };
  
  var foo = new Foo();
  </code></pre>
  
  <p>To have the text in the instance of foo I'm using bind:</p>
  
  <pre><code>var Foo =  function () {
      getFileText().then(this.showFile.bind(this));
  };
  </code></pre>
  
  <p>Is there any other way?</p>