daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Aug 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. intermediate javascript: assign a function with its parameter to a variable and execute later
  2. function alertMe($a)
  3. {
  4.    alert($a);
  5. }
  6.    
  7. //define the function
  8. function alertMe(a) {
  9.     //return the wrapped function
  10.     return function () {
  11.         alert(a);
  12.     }
  13. }
  14. //declare the variable
  15. var z = alertMe("Hello");
  16. //invoke now
  17. z();
  18.    
  19. var func = function() { alertMe("Hello") };
  20. // and later...
  21. func();
  22.    
  23. function buildIt(message) {
  24.     return function() { alertMe(message) };
  25. }
  26.  
  27. var func1 = buildIt("Hello");
  28. var func2 = buildIt("Pancakes");
  29. // And later...
  30. func1(); // says "Hello"
  31. func2(); // says "Pancakes"
  32.    
  33. var func = "alertMe('Hello')";
  34. eval(func);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top