The direct amount of the function, which is useful for functions that are used only once and need not be named. The following example, which has the fact function name, is used only as a self invocation.
Copy Code code as follows:
var f = function (x)
{
return x*x;
}
var f = function fact (x)
{
if (x<=1) return 1;
else return x*fact (x-1);
};
An array of arguments for the function: arguments object. Common Arguments[i] references, arguments.length, etc.
Object:
The method in the object definition (function), which is also a function, differs from the nested function in that it refers to the object entity through the keyword this.
Copy Code code as follows:
function Rectangle (W, h)
{
This.width = W;
This.height = h;
This.area = area;
This.enlarge = Rectangle_enlarge;
This.setsize = setSize;
Defining methods by constructors
function Rectangle_enlarge ()
{
This.width *= 2;
This.height *= 2;
}
function setSize (width, height)
{
if (Arguments.length < 2)
{
throw new Error ("Arguments less!");
}
else if (arguments.length >= 2)
{
This.width = width;
This.height = height;
}
}
function Area ()
{
Return (This.width * this.height);
}
function area1 ()
{
Alert (10);
}
}
Prototype objects and inheritance:
A prototype object is an ideal place to store methods and other common-sense attributes, equivalent to static fields in C #.