writes:
> Is there a way of constructing a "class" in JavaScript to access a
> private member of a different scope of the same type?
If I understand your question correctly (and that's by no means
certain), then the answer is no.
There is nothing in Javascript that distinguishes one object's "class"
from another (since there are no classes), so there is nothing that an
object of one type can do to another object, that one of another type
can't.
> This too doesn't work (though it seems like it should...). The only
> thing I've come up with is keeping track of my objects in a private
> static and referring to them later. Though I know this is horrible
> because it prevents objects from being garbage collected.
You want each instance of your type to have a value associated, that
another instance can access, but that objects of other types can't.
Your solution, to keep one mapping from instance to associated value,
that all instances have access to through the constructor, is the only
one I can think of. And it's not pretty (and hard to do, since objects
can't be used directly as keys for a map).
> Does anybody have any other ideas how to accomplish this in JavaScript
> without making a public this.method for accessing the privateKey?
No.
Javascript doesn't have access control. Trying to impose it will only
make your code convoluted and fragile.
Just document that nobody should fiddle with the value, and let others
shoot themselves in the foot if they really want to.
If this is client-side scripts, any determined attacker can get the
private key anyway, since he has complete control of the client.
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'