In JavaScript, functions can be nested.
For example:
function(){ funcrion square(x){ return x*x; } return square(10); }
In JavaScript, a function is bound to an object, and the function called by the object is called a method, which is easy to be confused with C#.
1. Function attributes
In the function body, you can get the number of actual parameters passed into the function through arguments.length.
function fun1 (x,y){ document.write(arguments.length()); //输出2,传入的参数是两个 } fun1();
2. Bind the function to the object
var fun1 = function () { alert(this.name); } var o = { name:"张三",fn : fun1 }; o.fn(); //输出 张三 var o = { name: "张三", fn: function () { alert(this.name) } } o.fn(); //输出张三