title: Adding prototype methods outside vs inside of constructor function
body: <p>I was learning prototype in JavaScript and wanted to ask you if the following code is correct:</p>
  
  <pre><code>function Shape() {
      Shape.prototype.duplicate = function() {
          console.log('Duplicate');
      }
  }
  
  function Circle() {
      Circle.prototype = Object.create(Shape.prototype);
  }
  </code></pre>
  
  <p>Or should I use this code:</p>
  
  <pre><code>function Shape() {
  }
  
  Shape.prototype.duplicate = function() {
      console.log('Duplicate');
  }
  
  function Circle() {
  }
  
  Circle.prototype = Object.create(Shape.prototype);
  </code></pre>