ulfben

using the Function type

Jan 9th, 2017
12,204
0
Never
4
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. }
Advertisement
Comments
  • User was banned
  • Rteuixl
    217 days
    # text 0.21 KB | 0 0
    1. Best t33n active cpx link daily updates!
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
    6.  
    7. Remove the @
  • User was banned
  • Comment was deleted
Add Comment
Please, Sign In to add comment