title: Why constructor property of object points to parent's constructor instead of F in extend function if constructor property is not overridden
body: <p>I'm discerning the famous JS's <code>extend</code> function:</p>
  
  <pre><code>function extend(parent, child) {
      var F = new Function();
      F.prototype = parent.prototype;
      child.prototype = new F();
      //child.prototype.constructor = Child
  }
  </code></pre>
  
  <p>I've commented out the line where the constructor property is overridden. If I create the objects in the following way:</p>
  
  <pre><code>var p = function p() {this.parent = true};
  var c = function c() {this.child = true};
  extend(p, c);
  console.log((new c()).constructor); //outputs reference to `p` constructor, why?
  </code></pre>
  
  <p>My question is why the constructor references <code>var p = function p() {this.parent = true};</code> instead of anonymous function that variable <code>F</code> points to? The manual on constructor property states that <code>constructor property returns a reference to the Object function that created the instance's prototype</code> and the instance prototype <code>new F()</code> was created by anonymous function. So why does it point to the other thing?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Is the following assumption I've made based on <code>HMR</code>'s answer correct?<br>
  When a new function is created, JS engine creates new empty object and sets <code>prototype</code> proprety of the function to point to this newly created object. Then JS engine adds a <code>constructor</code> property to this object pointing to the created function.</p>
  
  <p>So now to my case. When <code>var F = new Function()</code> JS engine:<br>
  1) creates new <code>F</code> function<br>
  2) creates new object (let it be <code>oF</code>)<br>
  3) sets prototype <code>F.prototype = oF</code><br>
  4) sets constructor <code>oF.constructor = F</code><br></p>
  
  <p>The same goes for <code>function p</code> which has its prototype <code>oP</code> with a constructor property set to <code>function p</code>. As we remember, <code>F.prototype</code> points to <code>oF</code> but after we execute the following line <code>F.prototype = parent.prototype</code> it is now points to <code>oP</code>. Then when we access <code>(new c()).constructor</code> property <code>new c()</code> object doesn't have it so JS engine starts looking backwards on prototypes and finds the property on <code>oP</code> pointing to <code>function p</code> - and this is excatly what I get.</p>