title: Extending a javascript object during the objects instantiation
body: <p>I have a library of javascript classes that inherit from each other using John Resig's simple Javascript inheritance library (<a href="http://ejohn.org/blog/simple-javascript-inheritance/" rel="nofollow">http://ejohn.org/blog/simple-javascript-inheritance/</a>)
  One of my classes (let's call it <em>parent</em>) has a number of child classes (<em>parent.child1</em>, <em>parent.child2</em>, etc) that extend the <em>parent</em> class and add their own methods.
  Normally, I would instatiate a child object by </p>
  
  <pre><code>ob=new parent.child1(ops)
  </code></pre>
  
  <p>However, when I instantiate a <em>parent</em> object, the creation options hash can include a member called <em>type</em>, which tells me that this object must actually be a <em>child</em> object.</p>
  
  <pre><code>ob= new parent({type:"child1"});
  </code></pre>
  
  <p>During the object creation, how can I make sure that the object created is an instance of <em>parent.child1</em>? If that is not possible, how can I make sure that at least the created object has all the methods and properties of <code>parent.child1.prototype</code>?</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT: A better example is to have a class called <em>employee</em> and then two classes that inherit from <em>employee</em> called <em>employee.engineer</em> and <em>employee.admin</em></p>