Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 105

Programming actionscript 3.0
Table of Contents

Advertisement

function rectArea(y:int):int // function closure defined
{
return x * y
}
return rectArea;
}
function bar():void
{
var x:int = 2;
var y:int = 4;
var myProduct:Function = foo();
trace( myProduct(4) ); // function closure called
}
bar(); // 160
Methods behave similarly in that they also retain information about the lexical environment
in which they were created. This characteristic is most noticeable when a method is extracted
from its instance, which creates a bound method. The main difference between a function
closure and a bound method is that the value of the
refers to the instance to which it was originally attached, whereas in a function closure the
value of the
keyword can change. For more information, see
this
on page
121.
keyword in a bound method always
this
"Bound methods"
Functions
105

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents