var myFunc:Function = function():void{
trace("test");
}
myFunc.call(); //"test"
myFunc(); //same thing as above
var multiplyWithEight:Function = makeMultiplierOf(8);
var result:Number = multiplyWithEight(2);
trace(result);
public function makeMultiplierOf(x:Number):Function{
return function(y:Number):Number{
return x * y; //notice; the function still have access to x when we call it later!
//that is a "closure"
};
}
Comments
0 B
|👍
/👎
0 B
|0 👍
/0 👎
0 B
|👍
/👎
0 B
|👍
/👎