title: Javascript sub prototyping
body: <p>I have a question about sub-prototyping.</p>
  
  <p>As example I want to do something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>var Foo = function() { this.Bar.prototype.Foo = this.Baz.prototype.Foo = this };
  Foo.prototype.is = "foo";
  Foo.prototype.Iam = function() { return this.is };
  
  Foo.prototype.Bar = function() {};
  Foo.prototype.Bar.prototype.is = "bar";
  Foo.prototype.Bar.prototype.Iam = function() { return this.Foo.is + this.is };
  
  Foo.prototype.Baz = function() {};
  Foo.prototype.Baz.prototype.is = "baz";
  Foo.prototype.Baz.prototype.Iam = function() { return this.Foo.is + this.is };
  
  var foo = new Foo();
  var bar = new foo.Bar();
  var baz = new foo.Baz();
  
  console.log(foo.Iam()); // output: foo
  console.log(bar.Iam()); // output: foobar
  console.log(baz.Iam()); // output: foobaz
  </code></pre>
  
  <p>To access the Foo-object within Bar and Baz I extend the prototype of Bar and Baz with <code>this.Bar.prototype.Foo = this.Baz.prototype.Foo = this</code>.</p>
  
  <p>My question is if there exists an easier way to do that and to access the main object Foo within Bar and Baz, or is this the common way to do that? The reason I want to do that is to create one main object <code>var x = new Foo()</code> and all sub objects can access the main object.</p>