5 ms·
This constructor makes three private instance variables: param, secret, and that. They are attached to the object, but they are not accessible to the outside, n
by trezor 18y ago
This constructor makes three private instance variables: param, secret, and that. They are attached to the object, but they are not accessible to the outside, nor are they accessible to the object's own public methods. They are accessible to private methods. Private methods are inner functions of the constructor.
Call me dim, but if you can define private members which can't even be accessed by public members and only in the constructor, how are they anything except local?
I might be doing needlessly geeky nitpicking here, but "private" has a standardized meaning in pretty much all OOP languages, and calling this private just seems silly.
Edit: Reading the whole thing, it seems the butchered public and not private. Making public something different all together, and having "privileged" being the actual, usual public-modifier.
Ah well. I never liked javascript ;)
- mechanical_fish 18y agoI don't think it's clicked for you yet. And when you say this: "private" has a standardized meaning in pretty much all OOP languages don't you mean "in C++ and Java"? Because Ruby's private is significantly different.
- trezor 18y agoAh well. I'll rephrase myself and say any OOP language I have any significant knowledge about then ;) But both C#, VB.Net and pretty much any OOP language I have touched has been like that. Granted I've seen different meanings for static and protected, but I've never seen this behaviour before. I'll simply admit my own ignorance, I guess.
- SwellJoe 18y agoWhen in doubt go to the source of the ideas, to see who got the labels wrong. C#, VB.Net, Java, and even C++ are nowhere near the source on OOP (and they are all in the same lineage...while JavaScript shares far more with Scheme and SmallTalk, and is thus on a quite different road). One should be careful about thinking "different" means "wrong".
- gnaritas 18y agoYou can stick public functions onto your object while you're in the constructor, that makes any variables local to the constructor available only via said public method, effectively capturing them in the closure created by the inner function. After the constructor dies, its environment is kept alive by any of those functions and it acts exactly like private instance variables in your other common OO languages.