Call can implement similar Object-oriented Inheritance:
Function person () {This. A = 'person '; this. B = function () {alert (' I \'m a person! ');} This. C = 'person \ 'C properties'; this. D = function () {alert ('person \ 'function D. ') ;};} function student () {person. call (this); this. A = 'student '; this. E = 'student class'; this. B = function () {alert ('I \'m a student');} This. F = function () {alert ('this is student \'s function. ');} // If person. call (this); put it here, then person will overwrite the student method} function main () {var student = new student (); student. D (); student. B ();} Main ();
Refer:
Callee
ReturnsFunctionObject, that is, the specified
FunctionObject Body.
[function.]arguments.callee
OptionalFunctionThe parameter is currently being executedFunctionObject Name.
Description
CalleeThe initial value of the attribute is being executed.Function
Object.
CalleeAttribute isArguments
A member of an object,It indicates the reference to the function object itself, which is conducive to anonymity
Recursion of functions or encapsulation of functionsFor example, the following example recursively calculates the sum of natural numbers from 1 to n. This attribute
It is available only when the related function is being executed. Note thatCalleeHas the Length attribute, which is sometimes
It is better for verification.Arguments. LengthIs the length of the real parameter,Arguments. callee. LengthYes
The length of the parameter to determine whether the length of the parameter is consistent with that of the actual parameter.
Example
Typical recursive functions: When called: Alert (sum (100 ));
The function contains a reference to sum itself. The function name is only a variable name. Calling sum inside the function is equivalent to calling
A global variable cannot reflect the call itself.CalleeIt will be a better method.
// Callee can print itself
Function calleedemo (){
Alert (arguments. callee );
}
// Used to verify Parameters
Function calleelengthdemo (arg1, arg2 ){
If (arguments. Length = arguments. callee. Length ){
Window. Alert ("verify that the length of the form parameter and real parameter is correct! ");
Return;
} Else {
Alert ("real parameter length:" + arguments. Length );
Alert ("parameter length:" + arguments. callee. Length );
}
}
// Recursive Calculation
VaR sum = function (n ){
If (n <= 0)
Return 1;
Else
Return N + arguments. callee (n-1)
}
VaR sum = function (n ){
If (1 = N) return 1;
Else return N + sum (n-1 );