Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <script>
  2.  
  3. /* TRADITIONAL WAY */
  4. doProcess(10, 20); // function call
  5. function doProcess(a, b) {
  6. // statements
  7. }
  8. /* Description: In this traditional way, function can also be called before it's defined.
  9.  
  10. END OF TRADITIONAL WAY */
  11.  
  12. /* FUNCTION EXPRESSION or FUNCTION LITERALS - MODERN WAY */
  13. var doProcess = function(a, b) {
  14. //
  15. }
  16. doProcess(10, 20); // function call - can't be before it's definition will through an error.
  17.  
  18. /* Description: Name of the function removed, and assigned to a variable
  19. Anonymous function assigned to a variable */
  20.  
  21. /* ASSIGNING FUNCTIONS TO OTHER VARIABLE */
  22. var f = doProcess; // assigment of function
  23. f(10,20); // function call
  24.  
  25. // OR
  26. function doProcess2(process1) {
  27. process1();
  28. }
  29. function doProcess() {
  30. //
  31. }
  32. doProcess2(doProcess);
  33.  
  34. /* IMMEDIATELY INVOKED FUNCTION EXPRESSION or SELF EXECUTABLE FUNCTION EXPRESSION */
  35. (
  36. function() {
  37. // statements
  38. }
  39. )();
  40. /* DESCRIPTION: Immediately invokes itself the moment it is defined. Can also have parameters.
  41. */
  42.  
  43. (
  44. function(a,b) {
  45. // statements
  46. }
  47. )(10,20);
  48.  
  49. /* RECEIVING VARIABLE NUMBER OF AGRUMENTS */
  50. function doSum() {
  51. var s = 0;
  52. for(var i = 0; i < arguments.length; i++) {
  53. s += arguments[i];
  54. }
  55. alert("Total Sum" + s.toString());
  56. }
  57.  
  58. function Get
  59.  
  60. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement