title: How do you find the root prototype constructor for a constructor in a prototype chain?
body: <p>I have a chain of constructors using prototype inheritance in JavaScript like so:</p>
  
  <pre><code>var Test = function(){};
  var Foo = function(){};
  var Bar = function(){};
  var Baz = function(){};
  Bar.prototype = new Baz();
  Foo.prototype = new Bar();
  Test.prototype = new Foo();
  </code></pre>
  
  <p>I want to write a function getRootConstructor() such that </p>
  
  <pre><code>getRootConstructor(Test) === Baz.
  </code></pre>
  
  <p>The goal was that I could do </p>
  
  <pre><code>getRootConstructor(Test).prototype = new UniversalBaseConstructor();
  </code></pre>
  
  <p>So I could add functionality to a constructor without breaking the prototype chain. This turns out to be very unintuitive.</p>