ulfben

using the Function type

Jan 9th, 2017
128
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×