title: JavaScript inheritance with .call(this)
body: <p>Code gotten from <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model" rel="nofollow">MDN</a>: </p>
  
  <pre><code>function Employee() {
      this.name = "";
      this.dept = "general";
  }
  
  function Manager() {
      Employee.call(this);
      this.reports = [];
  }
  
  Manager.prototype = Object.create( Employee.prototype );
  
  function WorkerBee() {
      Employee.call(this);
      this.projects = [];
  }
  
  WorkerBee.prototype = Object.create( Employee.prototype );
  
  var x = new WorkerBee();
  
  console.log( x );
  </code></pre>
  
  <p>Output: <code>WorkerBee {name: "", dept: "general", projects: Array[0]}</code></p>
  
  <p>What effect does <code>Employee.call(this);</code> have? I know from running the code that it is necessary for inheritance to be successful. The docs for <code>.call()</code> simply state, </p>
  
  <blockquote>
    <p>method calls a function with a given this value and arguments provided
    individually.</p>
  </blockquote>
  
  <p>OK so it calls the constructor <code>Employee()</code> but there is no <code>new</code> operator being used and no <code>return</code> that would return the object and it's properties. How does <code>Employee.call(this)</code> cause the child object to inherit the parent properties?</p>
  
  <p>If this line is left out only the <code>projects</code> array is present as a property.</p>