Simple as that, can we emulate the "protected" visibility in Javascript somehow?
views:
167answers:
3
+3
A:
Do this:
/* Note: Do not break/touch this object */
...code...
Or a bit of google found this on the first page:
http://blog.blanquera.com/2009/03/javascript-protected-methods-and.html
Aiden Bell
2009-06-18 20:28:57
What this guy is doing is just ducktyping to see if he's 'this' has the same method as the calling function... it cannot guarantee that's the same guy who's calling.
Pablo Cabrera
2009-06-18 20:42:46
What I'm trying to say is that I don't think that this way you can really protect your 'protected' stuff :P
Pablo Cabrera
2009-06-18 20:46:13
@Pablo, I agree totally ... but if you want that behavior as concrete semantics then JS isn't the language you want :P
Aiden Bell
2009-06-18 21:01:22
+1
A:
What could that possibly mean? You don't have classes.
I suppose you could analyze caller
to determine whether it meets some set of criteria for being permitted to call a method. This will be hideously inefficient and your criteria will always be spoofable.
chaos
2009-06-18 20:29:29
Not exactly true. In Javascript _everything_ is an object. You define classes using an active syntax, instead of a passive one. Composition vs. declaration.
Christopher
2009-06-18 20:32:57
@Christopher ... You are wrong, just because it is prototypical doesnt mean the prototypes are classes! Are they also interfaces?
Aiden Bell
2009-06-18 20:34:30
Well, okay. But what I mean is that you don't have a namespace of entity categorizations to which an object can be known to belong or not belong, which is what protected visibility normally keys on. You can't tell an inheritor from something that wants to look like an inheritor.
chaos
2009-06-18 20:37:02
Still, without proper classes we can have the concept of private members using JS Variable scoping tho
Pablo Cabrera
2009-06-18 20:37:08
I think languages that leave the semantics out and allow implementations (like decorators and such) are cool. Just a pain in the arse when you need a 'standard' effect.
Aiden Bell
2009-06-18 20:40:15