Function Definition
Function <Function Name> (<parameter list>)
{
<Function body>
}
A function can have either a return statement or no. If a function does not have a return statement, it only executes each statement in the function body and returns it to the caller undefined.
Functions can be nested in other functions, but cannot appear in loops or condition statements. (Function direct quantity exception)
Function Constructor
VaR <Object Name> = new function (<parameter list>, <function body>)
Function quantity
VaR <Object Name> = function (<parameter list>)
{
<Function body>
}
The Untitled function is directly created using the function, but its syntax also specifies that the function name can be specified, which is very useful in writing and calling its own recursive function.
Using functions is more convenient than using functions to construct functions.
To create a function object, the function name does not actually have any significance. It is just the name of the variable used to save the function, or a reference to the function.
A function can be passed as a parameter to another function or processed as a value.
The actual parameter arguments object of the function.
In a function, the identifier arguments has a special meaning. It is a special attribute of the called object and is used to reference the arguments object. The arguments object is like an array. You can obtain the parameter values passed to the function according to numbers.
The arguments object also defines the callee attribute to reference the currently executed function. This is very useful for untitled function calls.
Although there are fixed numbers of named parameters when defining a function, the parameter data passed to this function can be arbitrary.
A function is actually an object.
The Length attribute of a function indicates the number of declared parameters.
Each function has the prototype attribute, which references a predefined prototype object. A prototype object acts as a constructor using the new operator. It plays an important role in defining a new object type.
Ecmascript V3 defines the call () and apply () methods for all functions. You can use these two methods to call a function just like calling methods of other objects. The first parameters of call () and apply () are the objects of the function to be called. In the function body, this parameter is the value of the keyword "this. The remaining parameters of call () are the values passed to the function to be called. The apply () and call () methods are similar, except that the parameters passed to the function are specified by arrays.
For example:
F. Call (O, 1, 2 );
Equivalent to the following code
O. M = F;
O. m (1, 2 );
Delete o. m;