Reload interpretation in JavaScript and reload interpretation in javascript
There is a special data type in JavaScript-Function type. Every Function in JavaScript is a Function-type instance. Because the function is an object, the function name is actually a pointer to the function object and will not be bound to a function.
<pre name="code" class="html">function sum(num1,num2){return num1 +num2;}alert(sum(10,10)); //20var other = sum;alert(other(10,10)); //20sum = null;alert(other(10,10)); //20
Using a function name as a pointer to a function helps you understand why ECMAScript does not have the concept of function overloading.
function sum(num1){return num1 +100;} function sum(num1){return num1 +200;}alert(sum(200)); //400
Although two functions with the same name are declared, the subsequent functions overwrite the previous functions. The above is equivalent to the following code:
function sum(num1){return num1 +100;}sum = function(num1){return num1 +200;}alert(sum(200)); //400
When creating the second function, it actually overwrites the referenced first function variable sum.
Can javascript Functions be overloaded?
The reload of javascript Functions is different from that of java functions.
When defining a JavaScript function, the function name is the identifier of the function object. The number of parameters is only the attribute of the function. It is not feasible to implement overload by defining functions with different numbers of parameters.
When calling a function, js finds the corresponding function object through the function name, and matches the function with the expression parameter list in order according to the parameter defined by the function, removing unnecessary parameters, parameters that are not enough are processed by undefined, and then the function code is executed. Therefore, js overload functions must be implemented by determining the parameter values and types through function code.
When defining a function, you need to put the required parameters at the beginning of the parameter list, and the optional parameters are placed after the required parameters in the parameter list to facilitate function overloading.
Jequery or javascript implements partial page Overloading
I don't quite understand why? Hi me.