object that is being executed.
The Callee property is a member of a arguments object that represents a reference to the function object itself, which facilitates anonymous
The recursion of a function or the encapsulation of a function, such as the sum of the natural numbers of 1 to n in the following example. and the property
Available only if the related function is executing. Also note that callee has
function");
}
}
function Handlecaller () {
Callerdemo ();
}
callee
Returns the function object being executed, which is the body of the specified function object.
[function.] Arguments.callee
The optional function parameter is the name of the function object that is currently executing.
Description
The initial value of the Callee property is the Function object that is being executed
Callee property is a member of a arguments object that represents a reference to the function object itself, which facilitates anonymousThe recursion of a function or the encapsulation of a function, such as the sum of the natural numbers of 1 to n in the following example. and the propertyAvailable only if the related function is executing. Also note that callee has the length attribute, which is sometime
JS call method _ apply method _ caller attribute _ callee attribute
Address: http://aweber.blogbus.com/logs/46751586.html
I. Call MethodCall a method of an object to replace the current object with another object (in fact, it is to change the internal pointer of the object, that is, to change the content pointed to by this object ).JS Code
Return 1;ElseReturn n + arguments. callee (n-1)}Typical recursive functions:Var sum = function (n ){If (1 = n) return 1;Else return n + sum (n-1 );Call time: 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 callingA global variable cannot reflect the call
here.When we talk about call and apply, these two methods basically mean one thing.The difference is that the second parameter of call can be of any type, and the second parameter of apply must be an array or arguments.There is callee and caller. This is different from the call usage. Let's talk about it next time.Cal
. Class1.call (this) means that the Class1 object is used to replace this object. Then, does Class2 have all the attributes and methods of Class1, the c2 object can directly call the Class1 Method and Its Attributes. The execution result is: alert ("cc ");
That's right. This is how javaScript simulates inheritance in object-oriented systems, and implements multiple inheritance.
Function Class10 (){This. sho
Js apply/call/caller/callee/bind usage and Difference AnalysisI. call MethodCall a method of an object to replace the current object with another object (in fact, it is to change the internal pointer of the object, that is, to change the content pointed to by this object ).Js CodeCall ([thisObj [, arg1 [, arg2 [, [,. argN])ParametersThisObjOptional. Will be used
Fully understand the Javascript caller, callee, call, and apply Concepts [reprinted]
Before talking about the above concepts, we should first talk about the implicit parameter of the function in javascript: arguments Arguments This object represents the function being executed and the parameters of the function that calls it. [Function.] arguments [N]Parameter Function: option. Name of the f
following example recursively calculates the sum of natural numbers from 1 to n. This attributeIt is available only when the related function is being executed. Note that callee has the Length attribute, which is sometimesIt is better for verification. Arguments. length is the length of the real parameter, and arguments. callee. length isThe length of the parameter to determine whether the length of the pa
can print itselfFunction calleeDemo (){Alert (arguments. callee );}// Used to verify ParametersFunction 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.
context, the result and functionName. toStringThat is to say, The Decompilation Text of the function is displayed.The following example illustrates the usage of caller attributes:// Caller demo {Function callerDemo (){If (callerDemo. caller ){Var a = callerDemo. caller. toString ();Alert ();// The name Of The function that will call this function. Note that caller. name is not compatible with ie.Var callerFun = callerDemo. caller. nameAlert (callerFu
: "+ arguments. length); alert ("parameter length:" + arguments. callee. length); } var sum = function (n) { If (n return 1; else return N + arguments. callee (n-1) }
Typical recursive functions:VaR sum = function (n ){If (1 = N) return 1;Else return N + sum (n-1 );Call time: Alert (sum (100 ));The function contains a reference to sum itself. The function nam
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 (
. Length );}}// Recursive CalculationVaR sum = function (n ){If (n Return 1;ElseReturn N + arguments. callee (n-1)}Typical recursive functions:
VaR sum = function (n ){If (1 = N) return 1;Else return N + sum (n-1 );
Call time: 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 callingA global vari
. 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 CalculationVar sum = function (n ){If (n Return 1;ElseReturn n + arguments. callee (n-1)} Typical recursive fu
Window.alert ("Verify that the parameters and argument lengths are correct!") ");5 return;6} else {7 alert ("Argument length:" +arguments.length);8 alert ("Parameter length:" +arguments.callee.length);9}10}11//Recursive calculationvar sum = function (n) {if (n return 1;All elsereturn n +arguments.callee (n-1)17}18 Comparison of general recursive functions:19var sum = function (n) {if (1==n) return 1;+ else return n + sum (n-1);When invoked: Alert (SUM (100));Where the function contains a refere
variables in the Out function.Two features of closures:1, as a reference to a function variable-when the function returns, it is in the active state.2, a closure is when a function returns, a stack that does not release resources.Example 1:HTML codeCopy CodeThe code is as follows:Example 2:HTML codeCopy CodeThe code is as follows:Example 3:JS CodeCopy CodeThe code is as follows:Description: One of the key techniques is to create an additional execution environment by executing a single-line (in
The call method invokes one method of an object, replacing the current object with another object (in fact, changing the object's internal pointer, which changes the contents of the object's this point). JS code Call ([thisobj[,arg1[, arg2[, [,. ArgN]]]) parameter thisobj Optional. The object that will be used as the current object. Arg1, Arg2,, ArgN options available. The method parameter sequence will be
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.