function of JavaScript • For ext developers, I still hope that you will be able to understand and even skillfully use javascript native things. The function, then, is undoubtedly a very important concept. First of all, we know that a function is also a data type, and there are three ways to create a function. Each way they will be different: –function statement form – Function Direct Quantity form – constructor form • Function of arguments object –argument function One: Accept the function of the actual parameters of the role of –argument two: used to do the recursive Operation Chestnut Code
1 //function Functions2 //The main difference between the first two creation functions: The function statement, the JavaScript interpreter goes straight back, the other code executes from top to bottom .3 fun1 ();4 alert (fun2);5 fun2 ();6 //1:function Statement Form7 function fun1 () {8Alert'fun1 ...');9 };Ten //2: Form of the function direct quantity One varFun2 =function () { AAlert'fun2 ...'); - }; - the //the third type of constructor, which has a scope that differs from the first two, has a top-level scope - //3: constructor function form - varFUN3 =NewFunction ('x','y','return x+y;'); -Alert (FUN3 (Ten, -)); + - + A varK =1 ; at function Test () { - varK =2 ; - //to create a function of three different ways: - //function f () {return k;}; - //var f = function () {return k;}; - varf =NewFunction ('return k;'); in alert (f ()); - }; to test (); + - the * //arguments object: There is a arguments object inside each function $ function Test (x, y) {Panax Notoginseng //First function: Accept the actual parameters of a function -alert (arguments.length);//len = 3 theAlert (arguments[2]);//val = 3 + }; ATest1,2,3); the + //second effect: typically used for recursive operations - //Arguments.callee indicates that the current function itself is referenced $ function Fact (number) { $ if(Number <=1){ - return 1 ; -}Else { the returnNumber*arguments.callee (number-1); - }Wuyi }; the //Alert (Fact (5)); - varFact2 =fact; WuFact =NULL ; -Alert (Fact2 (5));
Recommended to you a beautiful article network www.fishcmonkey.com, learning to improve literary accomplishment