title: How to make superagent return a promise
body: <p>I've been learning Node/Javascript, using promises from the start (I don't know how to <em>not</em> use promises and often wonder how others get along without them).</p>
  
  <p>So I sometimes need to "promisify" simple stuff like reading a file with <code>fs</code>:</p>
  
  <pre><code>var readFile = function(path) {
      return new Promise(function(fulfill, reject) {
          fs.readFile(path, function(err, data) {
              if (err) { reject(err); }
              else { fulfill(data); }
          });
      });
  };
  </code></pre>
  
  <p>And that's been working great.  Now I need to do the same with <code>superagent</code>, but the chaining style it uses has me stuck.</p>
  
  <pre><code>var request = require('superagent');
  request.get(...).set(...).set(...).end(callback);  // stuck!
  </code></pre>
  
  <p>I'd like to replace the <code>end()</code> method (or ignore it and add a new method) with one that returns a promise.  Something like this...</p>
  
  <pre><code>var endQ = function() {
      return new Promise(function(fulfill, reject) {
          this.end(function(err, res) {     // "this" is the problem!
              if (err) { reject(err); }
              else { fulfill(res); }
          });
      });
  };
  
  // then I could say this:
  request.get(...).set(...).set(...).endQ().then(function(res) {
      // happiness
  }).catch(function(err) {
      // sad about the error, but so happy about the promise!
  });
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/13521833/javascript-add-method-to-object">This question here</a> has all kinds of advice about adding methods to objects, but it's hard to see what is definitive.  I was especially worried by <a href="https://stackoverflow.com/a/13522017/294949">this answer</a>.  Much of the advice centers around starting with the object's "class" and adding the function to <code>.prototype</code>.  Something like this....</p>
  
  <pre><code>// this part doesn't make sense
  var requestInstance = new Request();   // no such thing in request as far as I know
  requestInstance.prototype.endQ = endQ; // would be great, but no
  </code></pre>
  
  <p>See my problem?  I want the JS equivalent of "subclassing" the request "class" and adding a method, but since its a module, I need to treat the request class as more or less opaque.  </p>