Javascript call callee

Source: Internet
Author: User

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
Function
Object 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 functions
For 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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.