I already got lost looking at the dollar signs in JS code, honestly who does that!? Back in the old days it was used strictly for generated code, nowadays it's entirely associated with Jquery. I'n guessing you come from a very PHP oriented background.
function MyObject(){ var privateVar = 5; this.doWork = function() { Abort(privateVar); }}
function MyObject(){ var privateVar = 5; this.doWork = function(otherObj) { Abort(otherObj.privateVar); // what do you mean it's 'undefined'?! }};
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); }};
I did the getter/setter thing for a while, but eventually had to stop because it's specific to SpiderMonkey (and is even deprecated there!), and TurboSphere uses V8.
EDIT: Also, I agree with Radnen, drop the dollar signs, it's not idiomatic JavaScript. Either just let go of your C# background and feel the power of monkey-punching, or use the more accepted underscore.
I agree the dollar signs are pretty ugly, but... monkey-punching?! Not sure I've ever heard that expression before... what does it mean?
IIRC, the name came from "duck punching," like "duck typing." If it doesn't quack like a duck, punch it until it does. It is also known as "monkey patching," and some people like me get confused and just refer to it as "monkey punching."