8th Chapter function
1, the parameter has the difference between the formal parameter and the argument, the formal parameter is equivalent to the variable defined in the function, the argument is the parameter passed in when the function call at run time.
2. A function expression can contain a name , which is useful in recursion .
3. function definition expressions are particularly useful for defining functions that will only be used once, such as the sort () method or the immediate execution of functions.
4. A function declaration statement is advanced to the top of an external script or external function scope, so a function declared in this manner can be called by the code that appears before it is defined. However, a function defined with a function expression must be able to reference him, so it must be assigned to a variable whose declaration is advanced , but assigning a value to the variable is not advanced , so the function defined by the expression cannot be called before it is defined.
5. The return statement causes the function to stop executing and returns the value of its expression to the caller. If the return statement does not have an expression associated with it or there is no return statement, then return undefined to the caller.
6. A function declaration statement is not a true statement. They can appear in global code or embedded in other functions, but not in loops, conditional judgments, or try/catch/finally and with statements .
7, there are four ways to invoke the JS function : as a function , as a method , as a constructor , through their call () and the Apply () method is called indirectly .
8, as a function call , the call context, that is, the value of this is a global object , in strict mode, the calling context is undefined. Functions that are called as functions typically do not use the This keyword, but you can use this to determine if it is a strict pattern .
9, when the method does not need to return the value, it is best to return this directly, convenient chain call .
10. The keyword this does not have a scope limit, and the nested function does not inherit this from the function that called it. If the nested function is called as a method, its this value points to the object that called it. If a nested function is called as a function, its this value is not a global object or undefined. See 8.
11. If a function or method call is preceded by the keyword new, it constitutes a constructor call.
12. The constructor attempts to initialize the newly created object and uses the object as its calling context, so the constructor can use the This keyword to refer to the newly created object.
13. Use call () and apply () to implement the indirect invocation of the function. Two methods allow you to explicitly specify the this value that is required for the call, that is, any function can be invoked as a method of any object, even if the function is not a method of that object. The call () method method uses its own argument list as the argument for the function, and theapply () method requires that the parameter be passed in as an array , and the arguments array of the current function can be passed directly to another function's apply to invoke another function .
14. When a function is called, the arguments passed in are less than the number of parameters specified when the function is declared, and the remaining parameters are set to the undefined value .
15. You can use the annotation/*optional*/in the function definition to emphasize that the formal parameter is optional .
16, identifier arguments is a reference to an argument object, an argument object is a class array object , not a real array, it is an object that happens to have a numeric indexed property.
17. The argument object also defines the callee and caller properties. The callee property refers to the function that is currently executing, andcaller refers to the function that invokes the currently executing function .
18, use the object as an argument , call the function when the object is passed in, do not have to remember the order of the arguments.
19. the Length property of a function is a read-only property that represents the number of function parameters, that is, the number of arguments given when the function is defined, and usually the number of arguments that are expected to pass into the function when the function is called.
20. Functions created by the function () constructor do not use lexical scopes, instead, compilation of function body code is always performed at the top-level function (global scope) .
js-Authoritative Guide Study notes 8