One.
Declaration and invocation of functions
* 1 function Format: functions name (parameter 1, parameter 2 ...). ){
*//function body
* return result;
*
* }
* Format of Function call:
* Call directly: function name (value of parameter 1, value of parameter 2 ...) );
* Event Invocation: Event name = "function name ()";
* 2, a few highlights of the function declaration:
The declaration of the *① function name must conform to the small hump rule (first letter lowercase, then each word capitalized);
*② parameter list, can have parameters or can have no parameters, respectively called the parameter function, no parameter function;
*③ a parameter list when declaring a function, called a "parameter list" (the name of a variable);
* The argument list when calling the function, called the "argument list" (the value of the variable);
* In the function, the actual valid parameters depend on the assignment of the parameters, and the parameter that is not assigned will be undeined;
*④ function If the return value is required, return the result using return;
* When calling a function, use the var variable name = function name () to receive the returned result;
* If the function does not return a value, the accepted result is undefined;
Scope of variables in the *⑤ function:
* In the function, use VAR to declare the variable, the default is the function local variable, only in the function internal;
* Do not declare a default global variable without VAR (the global variable in the function must be used after a function call).
* The parameter list of the function, which is the function local variable, can only be called within the function;
The *⑥ function declaration has no precedence over the function call. That is, the call can be written before the declaration.
* Consle.log (NUM);
* Var num=10;
* The above code execution order:
* JS code execution, will be checked first, loading, that is, declaring variables, functions and other operations;
* and then into the execution phase (the assignment of the variable belongs to the execution phase)
* Therefore, the declaration of a function belongs to the check load case, and the function call belongs to the execution phase. So, the function call statement does not matter before the function declaration is written.
* So the above code executes the incoming
* Declaration Phase
* Var num;//declaring variables
* Function FuncN ()//declaring functions
* Implementation phase
*
* Console.log (NUM);
* num=10
* FuncN () executes the code in {} of the function.
*
Two.
Declaration and invocation of anonymous functions
* 1 declares an anonymous function that is directly assigned to an event;
* Window.onload=function () {}
* 2 declaring an anonymous function using a function expression;
* Declaring function expression: var func=function () {}
* Call Function Expression: func ();
* Using an anonymous function expression, the call statement must be declared after the statement, otherwise an error (compared to the general function declaration and the call difference)
* 3 Use the self-executing function to declare and invoke the anonymous function directly:
* ! function (parameter 1) {} (the value of parameter 1);//start with any operator, general use!
* (function () {} ())//use () to enclose the anonymous function and the following parentheses
* (function () {})//use () to wrap only anonymous function expressions
*
*
* Three types of writing features:
*① structure clear, beginning add! The end Plus () is not prone to confusion, recommended use;
*② can indicate that the anonymous function and the following () as a whole, recommended to use;
*③ cannot indicate that the function and after () are a whole and are not recommended for use.
* Three.
Properties inside a function
* Arguments Object
* 1 function: Used to save the argument list of the assigned value when the function is called.
* When we call a function and assign a value using an argument, the argument is actually saved to the arguments array, and the parameter can be called using arguments[n] even if there is no formal parameter;
* The number of 2arguments arrays, depending on the argument list, regardless of the parameter (starting from 0)
* However, when the nth position of the formal parameter, the argument, the arguents are present, the shape participates in the arguments is synchronous. (That is, one value is modified in the function and the other changes synchronously)
* 3.arguments.callee is an important attribute of arguments for returning a reference to the function where arguments is located;
* Arguments.callee () can invoke its own function execution;
* Calling the function itself within the function is called recursion, so Arguments.callee () is a common way of recursive invocation:
* this:
* Point to the scope of the function call statement who called the function this is pointing to who;
Getting started with JS functions