Re: kh2Bar 1.5.1 (Kingdom Hearts 2-style life bars)
Reply #18 –
Unless otherObj is not a type of MyObject you shouldn't be able to do that anyways. Plus, for that I'd suggest then you define a getter (but not a setter... setters are what should be avoided for private data).
function MyObject()
{
var privateVar = 5;
// I think this method is deprecated, but I don't know how else to do this with a closure:
this.__defineGetter__("var", function() { return privateVar; });
this.doWork = function(otherObj) {
Abort(otherObj.var);
}
};
But yeah I can see that if the other object is of type MyObject, you should be able to access private variables (get and set). This is useful for clone functions. If you wanted to go full-bore class interface I'd suggest you use one of the many out there, I know MooTools has one.