In JavaScript, each function is an instance of the functions class.
In other words, each defined function name is an instance of the functions type.
The function name holds a pointer to the function (the type instance pointer).
Can be implemented using the constructor of the function, and the last parameter is treated as a body of functions, such as:
var sum = new Function ("Num1", "num2", "return num1+num2"); Not recommended
1. No overloads
Because a pointer is stored in the function name and the same function name is redefined, the previously stored function is overwritten regardless of whether the parameter signature is consistent.
No overloads exist.
However, the overload of the function can be implemented, JavaScript, when the function passed in the parameters and the number of function signatures are not the same, you can still run (in the function body to determine whether the argument exists in the statement, to avoid errors).
This can also implement overloading of functions.
2. function declaration differs from function expression
JavaScript compiles the definition of the function in advance, either after the call, or the contents of the function body, such as:
alert (sum (10,10); Output 20
function sum (NUM1, num2) {
return NUM1 + num2;
}
When you use the expression of a function, the function is defined when it is compiled into an expression, so if the output of the example above is an error, such as:
alert (sum (10,10); Unexpected identifier
var sum = function (NUM1, num2) {
return NUM1 + num2;
}
3. Functions as values
Because a pointer is stored in the function name, the function can be passed in as a parameter inside another function, such as:
function Callsomefunction (someFunction, someargument) {
Return someFunction (someargument);
}
function Add10 (num) {
return num + 10;
}
var result1 = callsomefunction (ADD10, 10);
alert (RESULT1); 20
function getgreeting (name) {
Return "Hello," + name;
}
var result2 = callsomefunction (Getgreet, "Nicholas");
alert (RESULT2);
4. Function Internal Properties
"JavaScript" function type