title: JavaScript inheritance and constructors
body: <p>I'm trying to understand inheritance in JavaScript. I'm using prototype to link a child class to it's parent. But as soon as I'm defining the relationship the constructor of the parent class starts running.</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          function Person ()
          {
              window.alert('We\'ve got a new person!');
          }
  
          function King ()
          {
              window.alert('We\'ve got a new king!');
          }
  
          King.prototype = new Person();
  
          //King.prototype.constructor = King;
          //var erik = new King();
      &lt;/script&gt;
  </code></pre>
  
  <p>What's the correct way of using inheritance in JavaScript?</p>
  
  <p>The tutorial that started the confusion: <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript" rel="nofollow">https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript</a></p>