Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement