Not exactly.
What's happening here is that each time foo is called, a new activation object, containing the local variables "i" and "rectArea", is created and returned. Since these activation objects are completely independent of each other, they seem to exhibit some of the behaviour of types that are passed by value.
But try this ( in the context of your sample code, of course ;) ) :
var increaseCount4:Function = increaseCount3;
increaseCount3(); //output 1
increaseCount4(); //output 2

cheers,
till

Bryan Choi wrote:
>
> Hi, all.

> I'll show you some test code about the closure.
> You can see that 3 variables that is type of Function were assigned with
> foo() method .
> Genually, as you know, the primitive types is passed by value that is
> copied.
> So I think that this is also.

> How about you think?


> private function foo () : Function
> {
>     var i:int = 0;
>     function rectArea() : int { // function closure defined
>         return ++i;
>     }
>     return rectArea;
> }
> private function bar () : void
> {
>     var increaseCount1:Function = foo();
>     var increaseCount2:Function = foo();
>     trace("increaseCount1 : " + increaseCount1() );
>     trace("increaseCount1 : " + increaseCount1() );
>     var increaseCount3:Function = foo();
>     trace("increaseCount2 : " + increaseCount2() );
>     trace("increaseCount3 : " + increaseCount3() );
>     trace("increaseCount1 : " + increaseCount1() );
>     trace("increaseCount1 : " + increaseCount1() );
>     trace("increaseCount2 : " + increaseCount2() );
>     trace("increaseCount3 : " + increaseCount3() );
> }
> bar();
> // Output
> increaseCount1 : 1
> increaseCount1 : 2
> increaseCount2 : 1
> increaseCount3 : 1
> increaseCount1 : 3
> increaseCount1 : 4
> increaseCount2 : 2
> increaseCount3 : 2
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
>
>
>
> SPONSORED LINKS
> Web site design development
> <http://groups.yahoo.com/gads?t=ms&k=Web+site+design+development&w1=Web+site+design+development&w2=Computer+software+development&w3=Software+design+and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.sig=L-4QTvxB_quFDtMyhrQaHQ>
>       Computer software development
> <http://groups.yahoo.com/gads?t=ms&k=Computer+software+development&w1=Web+site+design+development&w2=Computer+software+development&w3=Software+design+and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.sig=lvQjSRfQDfWudJSe1lLjHw>
>       Software design and development
> <http://groups.yahoo.com/gads?t=ms&k=Software+design+and+development&w1=Web+site+design+development&w2=Computer+software+development&w3=Software+design+and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.sig=1pMBCdo3DsJbuU9AEmO1oQ>
>
> Macromedia flex
> <http://groups.yahoo.com/gads?t=ms&k=Macromedia+flex&w1=Web+site+design+development&w2=Computer+software+development&w3=Software+design+and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.sig=OO6nPIrz7_EpZI36cYzBjw>
>       Software development best practice
> <http://groups.yahoo.com/gads?t=ms&k=Software+development+best+practice&w1=Web+site+design+development&w2=Computer+software+development&w3=Software+design+and+development&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s=166&.sig=f89quyyulIDsnABLD6IXIw>
>
>
>
> YAHOO! GROUPS LINKS
>
>     *  Visit your group "flexcoders
>       <http://groups.yahoo.com/group/flexcoders>" on the web.
>       
>     *  To unsubscribe from this group, send an email to:
>        [EMAIL PROTECTED]
>       <mailto:[EMAIL PROTECTED]>
>       
>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>
>

--
______________________________________________
Till Schneidereit         Max-Brauer-Allee 259

phone ++49 40 98238528    20354 Hamburg
fax   ++49 40 98238530    germany
______________________________________________


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to