I have to say that Java has nothing to do with JavaScript, not the way I thought it was (JavaScript is a hyper-evolution of Java)
In JavaScript, a function is an object.
The parameter relationship between the function parameters of JavaScript and the expression calling the function is not one by one, they are a very faint relationship.
In JavaScript, there are three ways to define a function:
The first type:
1 function Add (number) 2 {3 alert (number+20); 4 }
The second type:
1 var add=function(number)2{3 alert (number+20); 4 }
The third type:
There is a function object in JavaScript, and all of the custom functions are function object types. All parameters received by a function object are of type string, where the last parameter is the body of the function to be executed, and the previous parameter is the one that the function really needs to receive.
1 var New Function ("number", "alert (number + 20);");
In JavaScript, each function has an implied object, arguments, that represents the arguments that the function actually passes. Without the concept of method (function) overloading, you can use arguments to implement overloaded functions of a function.
1 functionadd2 ()2 {3 if(1 = =arguments.length)4 {5Alert (arguments[0]);6 }7 Else if(2 = =arguments.length)8 {9Alert (Arguments[0] + arguments[1]);Ten } One Else if(3 = =arguments.length) A { -Alert (Arguments[0] + arguments[1] + arguments[2]); - } the } - -ADD2 (3); -ADD2 (3, 4); +ADD2 (3, 4, 5);
JavaScript's Function object