Community Member Profile
- Profile: /members/7856-Tim-Stevens.htm
- Comments: 4
- Points: 46
Recent Blog Comments By Tim Stevens
-
Circumventing Private Variables In Javascript Using Method Reassignment
Posted on Feb 21, 2011 at 1:01 PM
"Perhaps even arguing this point is useless as I suppose it boils down to a matter that is strictly personal :)" Yeah. You're right, in Java and .Net "this" is predictable, and a class can refer to it's public and private variables consistently. In Javascript... read more »
-
Circumventing Private Variables In Javascript Using Method Reassignment
Posted on Feb 21, 2011 at 12:43 PM
Which of these "inconsistencies" would you like to replace with var myObj.publicVar = 42? All of them? myObj.publicVar = 42; Object.defineProperty(myObj, "publicVar", { value: 42}); myObj["publicVar"] = 42; myObj = { inte... read more »
-
Circumventing Private Variables In Javascript Using Method Reassignment
Posted on Feb 21, 2011 at 12:17 PM
dunno what's so obtuse about closure...{ var privateVar; obj.publicVar; return obj; }; the underscore convention is definitely a matter of personal taste, like hungarian notation, both of which i dislike. The fun comes when, in the middle of your closure, the... read more »
-
Circumventing Private Variables In Javascript Using Method Reassignment
Posted on Feb 21, 2011 at 11:58 AM
Most languages have some method of changing private variables, whether through a reflection api, or through hacks like yours above - which is even more dangerous than reflection, as some, not all references to that variable are switched. Making variables "private" is generally abo... read more »



