On 03/08/2006 17:16,
ro****@gmail.co m wrote:
[snip]
Basically, I want to have a public static class method that could
access a private object's method.
If the 'private' method is defined by a function declaration within the
body of a constructor function:
function MyObject() {
function myPrivateMethod () {
}
}
then that is not possible: the identifier of the former is a property of
the variable object of the constructor function, not the function itself
nor the resulting object. That is, it's of local scope. The only way to
access such 'private' methods is through privileged functions; those
that are defined within the enclosing execution context, but then
explicitly exposed:
function MyObject() {
function myPrivateMethod () {
}
this.myPrivileg edMethod = function() {
// myPrivateMethod ()
};
}
The simplest solution is to make the 'private' method private by convention:
function MyObject() {
/* Do NOT call this function directly! */
this._myPrivate Method = function() {
};
}
though it may be better to add the method to the prototype object if is
has no need to access other 'private' data.
Mike
It may be possible to take an overly convoluted approach using shared
secrets, but this is unlikely to be worth the effort.