In Javascript, why does the constructor property point to the base-most constructor in the prototype chain?
<p>I'm curious about this design of Javascript, and perhaps any reasons for this architecture or design patterns that can be employed to take advantage of this.</p>

<p>The <code>constructor</code> property of an object is always a reference to the function that created that object, correct?</p>

<p>However, take this code:</p>

<pre><code>  function base()
  {
     this.SayHi = function ()
     {
        window.alert('Hi');
     };
  }

  function subclass()
  {
     this.SayBye = function ()
     {
        window.alert('Bye');
     };
  }

  subclass.prototype = new base();

  var s = new subclass();
  s.SayHi();
  s.SayBye();
  window.alert(s.constructor);
</code></pre>

<p>The last line will echo the constructor for <code>base</code>, even though we know <code>subclass</code> was called to create the object (otherwise <code>SayBye</code> would not work).</p>

<p>One potential work-around would be to simply do:</p>

<pre><code>subclass.prototype.constructor = subclass;
</code></pre>

<p>Perhaps a more concise way of asking my question is why is <code>s.constructor</code> equal to <code>subclass.prototype.constructor</code> and not <code>subclass.constructor</code>, since <code>s</code> is an instanceof subclass.  Thanks!</p>
