title: Extending a Promise in javascript
body: <p>I'm learning about classes and inheritance in javascript. I thought that the following is a fairly standard way of extending an existing object as I got the style from the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create" rel="noreferrer">MDN docs on Object.create</a></p>
  
  <p>I was expecting to see 'ok' and then 'Yay! Hello' in the console, but instead I go this error:</p>
  
  <pre><code>Uncaught TypeError: #&lt;MyPromise&gt; is not a promise
  at new MyPromise (&lt;anonymous&gt;:5:17)
  at &lt;anonymous&gt;:19:6
  </code></pre>
  
  <p>It looks like the Promise constructor is throwing an exception because it can tell that the object I've given it to initialise isn't a straightforward Promise. </p>
  
  <p>I want the Promise constructor to initialise my object as if it was a Promise object, so I can then extend the class. Why wouldn't they write the Promise constructor to work with this common pattern? Am I doing something wrong? Cheers for taking a look!</p>
  
  <pre><code>MyPromise = function(message, ok) {
      var myPromise = this;
      this.message = message;
      this.ok = ok;
      Promise.call(this, function(resolve, reject) {
          if(this.ok) {
              console.log('ok');
              resolve(myPromise.message);
          } else {
              console.log('not ok');
              reject(myPromise.message);
          }   
      }); 
  };  
  
  MyPromise.prototype = Object.create(Promise.prototype);
  MyPromise.prototype.constructor = MyPromise;
  
  (new MyPromise('Hello', true))
      .then(function(response) {console.log('Yay! ' + response);})
      .except(function(error) {console.log('Aww! ' + error);});
  </code></pre>
  
  <p>I was originally trying to make a BatchAjax class that you could use like:</p>
  
  <pre><code>(new BatchAjax([query1, query2]))
      .then(function(response) {console.log('Fires when all queries are complete.');}); 
  </code></pre>
  
  <p>It was just a bit of fun really. </p>