Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- /* TRADITIONAL WAY */
- doProcess(10, 20); // function call
- function doProcess(a, b) {
- // statements
- }
- /* Description: In this traditional way, function can also be called before it's defined.
- END OF TRADITIONAL WAY */
- /* FUNCTION EXPRESSION or FUNCTION LITERALS - MODERN WAY */
- var doProcess = function(a, b) {
- //
- }
- doProcess(10, 20); // function call - can't be before it's definition will through an error.
- /* Description: Name of the function removed, and assigned to a variable
- Anonymous function assigned to a variable */
- /* ASSIGNING FUNCTIONS TO OTHER VARIABLE */
- var f = doProcess; // assigment of function
- f(10,20); // function call
- // OR
- function doProcess2(process1) {
- process1();
- }
- function doProcess() {
- //
- }
- doProcess2(doProcess);
- /* IMMEDIATELY INVOKED FUNCTION EXPRESSION or SELF EXECUTABLE FUNCTION EXPRESSION */
- (
- function() {
- // statements
- }
- )();
- /* DESCRIPTION: Immediately invokes itself the moment it is defined. Can also have parameters.
- */
- (
- function(a,b) {
- // statements
- }
- )(10,20);
- /* RECEIVING VARIABLE NUMBER OF AGRUMENTS */
- function doSum() {
- var s = 0;
- for(var i = 0; i < arguments.length; i++) {
- s += arguments[i];
- }
- alert("Total Sum" + s.toString());
- }
- function Get
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement