On 03/03/2011 03:27 PM, Jeremiah Dodds wrote:
On Thu, Mar 3, 2011 at 8:56 AM, Marc Puts <[email protected] <mailto:[email protected]>> wrote:


     From my experience, the source version does not raise errors when you
    access private members from outside a class.
    On the one hand, that's a bad thing, but on the other hand, it
    does make
    it easy to do some quick & dirty calls during debugging.


Hmm, I'll keep that in mind.

On Thu, Mar 3, 2011 at 9:06 AM, Guilherme Aiolfi <[email protected] <mailto:[email protected]>> wrote:

    > Unless you mean you can't call private methods *at all*  in the
    build version, which would seem ... ridiculous.

    Well, you can if you are in the same class as the private method
    declaration.
    Otherwise, why would it be ridiculous? If it's private! It
    shouldn't be called anyway.


Right, I meant that if it was throwing an error in the build version because he was calling a private member from outside a class, that I would expect to see that error in the source version as well -- it's not like the call isn't there in the source version.

The reason for this is a technical one.

The Javascript language does not support access modifiers (everything is always public). In that regard, the qooxdoo notation of prefixing with single/double underscores is just a convention.

In the source version, the code that gets executed is exactly the code you wrote. There's nothing to block access to "private" members. In reality, there "private" members are public members that just happen to be prefixed with underscores.

In a build version, the generator knows about private members. Since private members never need to accessed from the outside, the generator does some optimizations such as shortening local member names. A member called __myDiary becomes something like __ab in the build version. Trying to access __myDiary from the outside raises an error (it's simply not there since it has been renamed).


Note that this only applies to private members. Protected members do not get renamed. They cannot be renamed, because not all users of the members can be known at compile time. I think that if you access a protected member from the outside in the build version, it won't raise an error. But I'm not 100% sure. :)


Regards,
Marc
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to