JavaScript - Invoking Methods that Reference this
<p>Not sure what I'm doing wrong here, I just want to be able to have functions of an object reference the object scope</p>

<p>myscipt.js</p>

<pre><code>function MyFoo () {
   this.name = 'myname';
}

function MyBar () {
   this.myFoo = new MyFoo();

   function setMyFoosName( name ) {
      this.myFoo.name = name;
   }
}
</code></pre>

<p>somepage.html</p>

<pre><code>&lt;scipt&gt;

$('document').ready( function() {
    $.myBar = new MyBar();
}

...
some action
...

$.myBar.setMyFoosName( 'new name' );

&lt;/script&gt;
</code></pre>

<p>this throws an exception:</p>

<pre><code>this.myFoo.name = name; this.myFoo is not defined
</code></pre>
