Tag: Ber alert call contains version span same else turn
The ECMAScript function does not implement overloading as it is in the traditional sense. In other languages, such as Java, you can write two definitions for a function, as long as the two defined signatures (the type and number of parameters that are accepted) are different. As mentioned earlier, the ECMASCIRPT function has no signature because its arguments are represented by an array containing 0 or more values. Without a function signature, the real overload is impossible.
If two functions with the same name are defined in ECMAScript, the name belongs only to the post-defined function. Take a look at the following example:
function addsomenumber (num) { return num +;} function addsomenumber (num) { return num +;} var // -
Here, the function addsomenumber () is defined two times. The first version adds 100 to the parameter, while the second version adds 200 to the parameter. Since the function defined above is overwritten by the later functions, the returned result is 300 when the function is called in the last line of code.
As mentioned earlier, you can mimic the overloads of a method by examining the type and number of parameters in the incoming function and reacting differently.
function Addsomenumber (NUM1) { var num1= arguments.length; if (1 = = num1) {var num2= arguments[1]; Alert ("High:" +num1+ ", Width:" +num2); Else { alert ("high =:" +NUM1);} }
Personal understanding Shallow, welcome correction!
After the timely replenishment ~
"END"
How to implement the overloading of JS function