title: JavaScript inheritance: Object.create vs new
body: <p>In JavaScript what is the difference between these two examples:</p>
  
  <p>Prerequisite:</p>
  
  <pre><code>function SomeBaseClass(){
  }
  
  SomeBaseClass.prototype = {
      doThis : function(){
      },
  
      doThat : function(){
      }
  }
  </code></pre>
  
  <p>Inheritance example A using Object.create:</p>
  
  <pre><code>function MyClass(){
  }
  
  MyClass.prototype = Object.create(SomeBaseClass.prototype);
  </code></pre>
  
  <p>Inheritance example B using the new keyword</p>
  
  <pre><code>function MyClass(){
  }
  
  MyClass.prototype = new SomeBaseClass();
  </code></pre>
  
  <p>Both examples seem to do the same thing. When would you chose one over the other?</p>
  
  <p>An additional question:
  Consider code in below link (line 15), where a reference to the the function's own constructor is stored in the prototype. Why is this useful?</p>
  
  <p><a href="https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageLoader.js" rel="noreferrer">https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageLoader.js</a></p>
  
  <p>Excerpt (if you don't want to open the link):</p>
  
  <pre><code>THREE.ImageLoader.prototype = {
  
      constructor: THREE.ImageLoader
  }
  </code></pre>