Re:This is the page that made doing OOP in Javascript click ...
by gnaritas on Thursday September 11, 2008 @04:09PM
(#301714)
You 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.
Re:This is the page that made doing OOP in Javascript click ...
by mechanical_fish on Thursday September 11, 2008 @01:40PM
(#301577)
I 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.
Re:This is the page that made doing OOP in Javascript click ...
by trezor on Thursday September 11, 2008 @01:54PM
(#301597)
Ah 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.
Re:This is the page that made doing OOP in Javascript click ...
by SwellJoe on Friday September 12, 2008 @04:57AM
(#302257)
When 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".
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 ;)