SHARE
TWEET

using the Function type

ulfben Jan 9th, 2017 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var myFunc:Function = function():void{
  2.     trace("test");
  3. }
  4.  
  5. myFunc.call(); //"test"
  6. myFunc(); //same thing as above
  7.  
  8. var multiplyWithEight:Function = makeMultiplierOf(8);
  9. var result:Number = multiplyWithEight(2);
  10. trace(result);
  11.        
  12.  
  13. public function makeMultiplierOf(x:Number):Function{
  14.     return function(y:Number):Number{
  15.         return x * y; //notice; the function still have access to x when we call it later!
  16.                         //that is a "closure"
  17.     };
  18. }
RAW Paste Data
Top