Function quantity. It is applicable to functions that are only used once and do not need to be named. In the following example, although there is a fact function name, the latter is only used for self-calling.
CopyCode The Code is 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 );
};
Parameter array of the function: arguments object. Common arguments [I] References, arguments. length, etc.
Object:
Methods In object definition (function) are actually a function. The difference with nested functions is that object entities are referenced by the keyword "this.Copy codeThe Code is as follows: function rectangle (W, H)
{
This. width = W;
This. Height = h;
This. Area = area;
This. Enlarge = rectangle_enlarge;
This. setsize = setsize;
// Use the constructor to define a method
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 for storing methods and other common sense attributes, which is equivalent to a static field in C.