title: Polymorphism Example usage error in JavaScript
body: <p>This is an example to demonstrate polymorphism example, at which if I remove following lines:</p>
  
  <pre><code>Employee.prototype= new Person();
  Employee.prototype.constructor=Employee;
  </code></pre>
  
  <p>there is still no effect on the program and it gets the similar results. If so, how does this example demonstrates polymorphism? Commenting those lines, I see there are 2 functions which when call return results based on their own <strong>getInfo</strong> functions; so, where is the magic?</p>
  
  <p><strong>HTML:</strong> </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function Person(age, weight) {
      this.age=age;
      this.weight=weight;
      this.getInfo=function() {
        return "I am " + this.age + " years old " +
          "and weighs " + this.weight +" kilo.";
      }
    }
    function Employee(age, weight, salary){
      this.salary=salary;
      this.age=age;
      this.weight=weight;
      this.getInfo=function() {
        return "I am " + this.age + " years old " +
          "and weighs " + this.weight +" kilo " +
          "and earns " + this.salary + " dollar.";
      }
    }
    Employee.prototype= new Person();
    Employee.prototype.constructor=Employee;
  // The argument, 'obj', can be of any kind
  // which method, getInfo(), to be executed depend on the object
  // that 'obj' refer to.
    function showInfo(obj) {
      document.write(obj.getInfo()+"&lt;br&gt;");
    }
    var person = new Person(50,90);
    var employee = new Employee(43,80,50000);
    showInfo(person);
    showInfo(employee);
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <p><a href="https://i.stack.imgur.com/ELajA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ELajA.png" alt="enter image description here"></a></p>
  
  <p><strong>Reference</strong></p>
  
  <p><a href="http://w3processing.com/index.php?subMenuItemId=329" rel="nofollow noreferrer">http://w3processing.com/index.php?subMenuItemId=329</a></p>