Gerald S wrote:
> but if i do it the .prototype-way, there is another problem. consider
> the following situation:
>
>
> item = function () {
> var privateVar;
>
> function doInternalStuff();
> }
>
> item.prototype.myMethod1 = function() { .. }
> item.prototype.myMethod2 = function() { .. }
> item.prototype.myMethod3 = function() { .. }
> ...
> item.prototype.myMethod999 = function() { .. }
>
>
> two issues:
> 1) i can't access privateVar from my myMethodXXX methods (or can i?)
> 2) i can't call doInternalStuff() from my myMethodXXX methods
>
> i could expose both to the public, but is there a way to keep them
> private AND use them. any patterns ?
>
Javascript doesn't really support private variables. Your best action is
simply to use some convention to indicate that they are private (e.g. a
leading underscore on the name) and then not access them from outside the
appropriate functions.
Received on Tue Feb 7 21:28:40 2006