[mtasc] visibility of members in lambdas?
Ralf Bokelberg
info at bokelberg.de
Sun Jan 15 16:02:21 CET 2006
The concept is called closure. I'm sure, google knows a lot about it.
Cheers,
Ralf.
EECOLOR wrote:
> Can you explain that better? Curious :)
>
> Greetz EE
>
>
> At 11:45 15-1-2006, you wrote:
>
>> Maybe, if you are a Javaprogrammer, you feel uncomfortable with
>> anoynmous functions. But to me, the "memory problem" is exactly the
>> cause to use anonymous functions.
>>
>> Cheers,
>> Ralf.
>>
>> EECOLOR wrote:
>>
>>> This can cause memory problems. Cause the activation object of
>>> function b (the scope where local function variables are saved) is
>>> not removed at the end of function b.
>>> If you write the code like this, the memory problem will not exist:
>>> var c = function()
>>> {
>>> var ref = arguments.callee.ref;
>>> ref.b();
>>> };
>>> c.ref = this;
>>> More infomation on:
>>> http://timotheegroleau.com/Flash/articles/scope_chain.htm
>>>
>>> Greetz Erik
>>>
>>> At 21:31 14-1-2006, you wrote:
>>>
>>>> Actually, i also have to define a reference to b. This makes things
>>>> really ugly.
>>>>
>>>> class A {
>>>>
>>>> public function b(){
>>>> var ref = this;
>>>> var c = function(){
>>>> ref.b();
>>>> }
>>>> c();
>>>> }
>>>> }
>>>>
>>>> Wouldn't it be much cleaner and less errorprone, if we could simply
>>>> do it like this (b remains private and can be accessed without ref):
>>>>
>>>> class A {
>>>>
>>>> private function b(){
>>>> var c = function(){
>>>> b();
>>>> }
>>>> c();
>>>> }
>>>> }
>>>>
>>>> And yes, this is a endless loop, it's just ment as an example to
>>>> deomstrate problems with the access of members.
>>>> r.
>>>>
>>>>
>>>>
>>>> Ralf Bokelberg wrote:
>>>>
>>>>> With mtasc i have to make a member public, if i need to access it
>>>>> from a lambda (anonymous function), even if this lambda is
>>>>> declared inside of the class.
>>>>> class A {
>>>>> public function b(){
>>>>> var c = function(){
>>>>> b();
>>>>> }
>>>>> c();
>>>>> }
>>>>> }
>>>>> b has to be public because of the access in c.
>>>>> I wonder, if this is really useful? Somehow i have the feeling, it
>>>>> casts a shadow on lambdas, which are a very powerful tool in my
>>>>> opinion. Couldn't we allow access, as long as we are inside of the
>>>>> class which declares b?
>>>>> Cheers,
>>>>> Ralf.
>>>>> -- MTASC : no more coffee break while compiling
>>>>
>>>>
>>>>
>>>> --
>>>> MTASC : no more coffee break while compiling
>>>
>>>
>>>
>>> --
>>> MTASC : no more coffee break while compiling
>>
>>
>> --
>> MTASC : no more coffee break while compiling
>
>
>
>
> --
> MTASC : no more coffee break while compiling
More information about the mtasc
mailing list