There are three ways in which the function functions are defined:
1.function statement form; 2. The form of the direct amount of the function 3. The first two ways to create functions in the form of constructors: Function statement form, JavaScript interpreter directly to find and explain;
The equivalent of the JS code to explain the function statement form; the other code executes from top to bottom.
It can be understood that the first one can be called at any location, whereas the second is only called after the definition; the third has a top-level scope
Arguments object,
There is a arguments object inside each function
1. Actual parameters of the receive function 2. For recursive operations
//function Functions//three ways of definition: 1.function statement form; 2. form of direct quantity of function 3. Form of constructor function//the first two ways to create functions are: Function statement form, JavaScript interpreter directly to find and explain;//the equivalent of the JS code to explain the function statement form; the other code executes from top to bottom.//It can be understood that the first one can be called at any location, whereas the second is only called after the definition;//arguments object with a arguments object inside each function//1. Actual parameters of the receive function 2. For recursive operations//fun1 (); Call Fun1 ...//fun2 (); FUN2 is not a function//alert ("1" +typeof fun2),//undefined, equivalent to a definition, but without explaining the function body//1.function statement form, which is generally used in this//can be called at any locationfunctionfun1 () {alert ("Call fun1 ...");};//2. Form of direct amount of function//can only be called after a definitionvarFun2 =function() {alert ("Call fun2 ...");};//alert ("2" +typeof fun2);//function//fun2 (); Call Fun2 ...//3. Form of the constructor function//Scopes are different from the first two, with top-level scopesvarFUN3 =NewFunction ("x", "Y", "return x+y;"));//alert (FUN3 (10,20));varK = 1;functionTest () {varK = 2; //Create a function of three different ways//function f () {return k;}; Returns 2, returns the local K//var f = function () {return k;}; Returns 2 varf =NewFunction ("return k;");//returns 1alert (f ());//test ();//arguments object with a arguments object inside each function//1. Actual parameters of the receive function 2. For recursive operationsfunctiontestarguments (x, y) {alert (arguments); //[Object Arguments]alert (arguments.length);//3Alert (arguments[1]);//2 };//testarguments (a);functiontestarguments1 (number) {if(number<=1) { return1; }Else{ returnNumber*arguments.callee (NUMBER-1);//calling the function itself //Why not use Testarguments1 (number-1) to replace Arguments.callee (number-1)}};alert (Testarguments1 (5)));// -
JavaScript (ii) function definitions and arguments use