The ECMAScript function does not have an attribute for the signature, so there is no overload in the ECMAScript function.
The presence of arguments in JavaScript can compensate for the lack of overloading of functions in JavaScript.
The parameters in a function in JavaScript are saved as an array, so when a function is called in JavaScript, the arguments passed by the function are not limited by the number of arguments we set when we define the function. That is, if we give a function to define 2 parameters, we pass the time can not pass, can pass one, can also pass two, pass three ... Can be, not affected by the number of function arguments. Arguments is similar to an array (but not a real array object), you can also use square brackets to access each of its values as an array, and use Arguments.length to determine the number of arguments.
It should be said that we can pass parameters to ECMAScript (JavaScript is the implementation of the ECMAScript standard) function arbitrarily, and can access these parameters through the arguments object.
Use of arguments:
function Myfun () {console.log (arguments.length);} Myfun ("1", "2");//2myfun ("1");//1myfun ();//0
function Myfun (num1,num2) {if (arguments.length = = = 1) {Console.log (arguments[0]);} else if (arguments.length = = 2) { Console.log (Arguments[0]+arguments[1]);} else if (arguments.length = = = 3) {Console.log (num1+num2+arguments[2]);} else {Console.log (arguments[0]+ "" +num1);}} Myfun (1);//1myfun (//3myfun);//6myfun ();//undefined undefined
Named parameters can be used with arguments
Unlike other OO languages, in ECMAScript, all parameters are passed as values, and it is not possible to pass parameters by reference (after all, the values of the parameters are saved in arguments).
The callee property is also defined in the arguments object to refer to the currently executing function, for example, in recursion:
function factorial (num) {if (num <=1) {return 1;} else {return Num*arguments.callee (num-1);}} Console.log (factorial (5));//120
Understanding the arguments object in JavaScript parameters