javascript - accessing private member variables from prototype-defined functions
<p>Is there any way to make "private" variables (those defined in the constructor), available to prototype-defined methods?</p>

<pre><code>TestClass = function(){
    var privateField = "hello";
    this.nonProtoHello = function(){alert(privateField)};
};
TestClass.prototype.prototypeHello = function(){alert(privateField)};
</code></pre>

<p>This works:</p>

<pre><code>t.nonProtoHello()
</code></pre>

<p>but this doesn't:</p>

<pre><code>t.prototypeHello()
</code></pre>

<p>I'm used to defining my methods inside the constructor, but am moving away from that for a couple reasons.</p>

<p>thanks!</p>

<p>-Morgan</p>

<hr>

<p>Thanks sktrdie,</p>

<p>That works, it would be nice not to have to create the this.accessPrivateField. If my "hello" function is defined inside the constructor, privateField is in the scope chain of the function, so I can treat privateField as I would a private field in java. It's a little more cumbersome to set up accessors (this.accessPrivateField), and then, privateField isn't really private any more.
I know javascript isn't java, but I like java!</p>

<p>-Morgan</p>
