title: Extending the built-in javascript Promise
body: <p>I'm trying to extend the javascript promise with a new method. This new method in this case is called <code>foo</code>, which really does something like this:</p>
  
  <pre><code>Promise.foo = function(arg) {
    return this.then( function(result) {
      return result.foo(arg);
    });
  };
  </code></pre>
  
  <p>So in short, the foo() function is a shortcut for waiting for a promise to resolve and then calling foo() on the result.</p>
  
  <p>The nature of this function is that it can be chained, just like <code>then()</code> can.</p>
  
  <pre><code>myPromise.foo(a).foo(b).foo(c);
  </code></pre>
  
  <p>I feel like this should be possible, but I'm just not sure what the right path is.</p>
  
  <p>This is what I've tried:</p>
  
  <pre><code>var FooPromise = function() {
     Promise.apply(this, arguments);
  }
  
  FooPromise.prototype = Object.create(Promise.prototype);
  FooPromise.foo = function(arg) {
    return this.then( function(result) {
      return result.foo(arg);
    });
  };
  </code></pre>
  
  <p>To test it out:</p>
  
  <pre><code>var test = new FooPromise(function(res, rej) {
     res('bla');
  });
  </code></pre>
  
  <p>In firefox this gives me:</p>
  
  <pre><code>TypeError: calling a builtin Promise constructor without new is forbidden
  </code></pre>
  
  <p>In Node:</p>
  
  <pre><code>TypeError: #&lt;Promise&gt; is not a promise
  </code></pre>
  
  <p>Is this just a limitation of javascript, or is there a way around this?</p>