'this' in function inside prototype function
<p>I basically have an object, extended with a function through its prototype. Inside that function, another function exists, however when using <code>this</code> in this nested function, it does not seem to refer to the object, but the function.</p>

<p>For example,</p>

<pre><code>var sampleObject = function() {
 this.foo = 123;
}

sampleObject.prototype.getFoo = function() {
 var nested = function() {
  return this.foo;
 }
 return nested();
}

var test = new sampleObject();

window.alert(test.getFoo()); // undefined
</code></pre>

<p>The <code>this.foo</code> does not refer to the 123 value, but is undefined as this refers to the nested function, in which no <code>foo</code> exists. How can I access the 123 value from the nested function?</p>

<p>Thanks.</p>
