title: There is something about Javascript inheritance that I can't understand
body: <p>I was reading <a href="https://developer.mozilla.org/en-US/docs/Introduction_to_Object-Oriented_JavaScript" rel="nofollow noreferrer">Introduction to Object-Oriented JavaScript</a> from Mozilla Developer Network, time to learn so serious Javascript before start using node.js.</p>
  
  <p>Anyway, inheritance thing seems so obscure to me. Copy and paste from the documentation:</p>
  
  
  
  <pre class="lang-javascript prettyprint-override"><code>// define the Person Class
  function Person() {}
  
  Person.prototype.walk = function(){
    alert ('I am walking!');
  };
  Person.prototype.sayHello = function(){
    alert ('hello');
  };
  </code></pre>
  
  <p>This is easy, but things get complicated with <code>Student</code> inheritance. Does anyone else think that the following three statements do essentially the same thing?</p>
  
  <pre class="lang-javascript prettyprint-override"><code>// define the Student class
  function Student() {
    // Call the parent constructor
    Person.call(this);
  }
  
  // inherit Person
  Student.prototype = new Person();
  
  // correct the constructor pointer because it points to Person
  Student.prototype.constructor = Student;
  </code></pre>
  
  <p>I understand the first one (calling the parent constructor) because is so similar to Java, PHP and so on. But then problems begin.</p>
  
  <p>Why there is the need of calling <code>Student.prototype</code> <s>and <code>Student.prototype.constructor</code></s>?</p>
  
  <p>A clear explanation is needed. Why this code:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>// define the Student class
  function Student() {
    // Call the parent constructor
    Person.call(this);
  }
  
  var student1 = new Student();
  </code></pre>
  
  <p>is not enough for inheritance to work?</p>
  
  <p><strong>EDIT</strong>: regarding the constructor thing, it has been already answered <a href="https://stackoverflow.com/questions/8453887/why-is-it-necessary-to-set-the-prototype-constructor">here</a>.</p>