[flexcoders] [FLEX2:B3] I think that a variable of the Function type is passed by value, right?

2006-05-26 Thread Bryan Choi





Hi, all.

I'll show you sometest code 
about the closure.
You can see that3 variables that is type of 
Functionwere 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 
: 1increaseCount1 : 2increaseCount2 : 1increaseCount3 : 
1increaseCount1 : 3increaseCount1 : 4increaseCount2 : 
2increaseCount3 : 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
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  









Re: [flexcoders] [FLEX2:B3] I think that a variable of the Function type is passed by value, right?

2006-05-26 Thread Till Schneidereit



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=msk=Web+site+design+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=L-4QTvxB_quFDtMyhrQaHQ 
  Computer software development 
 http://groups.yahoo.com/gads?t=msk=Computer+software+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=lvQjSRfQDfWudJSe1lLjHw 
  Software design and development 
 http://groups.yahoo.com/gads?t=msk=Software+design+and+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=1pMBCdo3DsJbuU9AEmO1oQ 
 
 Macromedia flex 
 http://groups.yahoo.com/gads?t=msk=Macromedia+flexw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=OO6nPIrz7_EpZI36cYzBjw 
  Software development best practice 
 http://groups.yahoo.com/gads?t=msk=Software+development+best+practicew1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=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



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  












Re: [flexcoders] [FLEX2:B3] I think that a variable of the Function type is passed by value, right?

2006-05-26 Thread Bryan Choi



Hi Till,



I got it now.



I didn't know that I was wrong.



Thank you for your help.



Regards,

Bryan Choi.



- Original Message - 

From: Till Schneidereit [EMAIL PROTECTED]

To: flexcoders@yahoogroups.com

Sent: Friday, May 26, 2006 7:32 PM

Subject: Re: [flexcoders] [FLEX2:B3] I think that a variable of the Function type is passed by value, right?





 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=msk=Web+site+design+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=L-4QTvxB_quFDtMyhrQaHQ 

 Computer software development 

 http://groups.yahoo.com/gads?t=msk=Computer+software+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=lvQjSRfQDfWudJSe1lLjHw 

 Software design and development 

 http://groups.yahoo.com/gads?t=msk=Software+design+and+developmentw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=1pMBCdo3DsJbuU9AEmO1oQ 

 

 Macromedia flex 

 http://groups.yahoo.com/gads?t=msk=Macromedia+flexw1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=166.sig=OO6nPIrz7_EpZI36cYzBjw 

 Software development best practice 

 http://groups.yahoo.com/gads?t=msk=Software+development+best+practicew1=Web+site+design+developmentw2=Computer+software+developmentw3=Software+design+and+developmentw4=Macromedia+flexw5=Software+development+best+practicec=5s=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

 __

 

 

  Yahoo! Groups Sponsor ~-- 

 Get to your groups with one click. Know instantly when new email arrives

 http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/nhFolB/TM

 ~- 

 

 --

 Flexcoders Mailing List

 FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt

 Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 

 Yahoo! Groups Links

 

 

 

 

 

 

 







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: