document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5.     <title>Callbacks</title>
  6. </head>
  7. <script type="text/javascript">
  8.  
  9.     function q(string, pFunction)
  10.     {
  11.         console.log(string);      
  12.         console.log("userData is a function.");
  13.         console.log(pFunction.toString());
  14.         pFunction(alert);  // Run the function.
  15.     }
  16.  
  17.    
  18.     q   ("String.", function (callback1)  // Define the function.
  19.                     {
  20.                         console.log("Doing something.");
  21.                         callback1("Alert 1!");
  22.                     }
  23.         );
  24.  
  25.    
  26.     // This does the same.
  27.     function function1 (callback1)  // Define the function.
  28.     {
  29.         console.log("Doing something.");
  30.         callback1("Alert 2!");
  31.     }
  32.    
  33.     function1(alert);  // Run the function.
  34. </script>
  35.  
  36. <body>
  37.  
  38. Body.
  39.  
  40. </body>
  41. </html>
');