title: Bluebird Promise Scope
body: <p>I have just started using promises in attempt to cleanup some 'callback hell'.</p>
  
  <p>I've decided on trying bluebird and I am running it in the browser but immediately ran into scoping problems.</p>
  
  <p>Is there a way of setting the thisArg in a new Promise? The below example shows that the 'this' value inside the promise resolver is set to the browser window, but I'd like it set to the surrounding scope so I can easily access member variables.</p>
  
  <p>I noticed there is a .bind() method but it only scopes the 'then()' method, not the promise. I also realize I can have 'var me = this' just before the promise and use closure, but I wanted to avoid it if possible.</p>
  
  <pre><code>function MyObject() {
      this.value = 7;
  }
  
  MyObject.prototype.getValue = function () {
      return new Promise(function (resolve) {
          // some request/processing that takes a long time
          var result = Ajax.request(...);
  
          resolve({
              value: this.value,
              result: result
          });
          // 'this' is set to window instead of the instance,
          // resulting in this.value as undefined
      });
  }
  
  var obj = new MyObject();
  obj.getValue().then(function (value) {
      console.log(value); // preferably outputs 7
  })
  </code></pre>