, and when you call the function testaguments, you will find that "undefined" is displayed, indicating that the property is not arguments. That is, arguments is not an array object.CallerReturns a reference to the function that called the current function.Functionname.callerThe FunctionName object is the name of the function being executed.DescriptionFor a function, the caller property is defined only when
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
javascript| concept
Before you mention the above concepts, first of all, let's talk about the implied parameters of functions in javascript: arguments
Arguments
The object represents the function being executed and the arguments of the function that called it.
[function.] Arguments[n]Parameter function: option. The name of the Function object that is currently executing. N: Options. The 0-based parameter value index to pass to the Function object.Description
Arguments is a hidden object that is
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
() {This.initialize.apply (this, arguments);}}}Parsing: From the code perspective, the object contains only one method: Create, which returns a function, the class. But it's also a class.constructor, which calls initialize, which is the initialization function defined at the time the class is created. Through this way,You can implement the class creation pattern in prototypeExample:var vehicle=class.create ();vehicle.prototype={Initialize:function (type) {This.type=type;}Showself:function () {A
starts. The following example details these properties:Copy codeThe Code is as follows:// Usage of the arguments object.Function ArgTest (a, B ){Var I, s = "The ArgTest function expected ";Var numargs = arguments. length; // obtain the value of the passed parameter.Var expargs = ArgTest. length; // obtain the value of the expected parameter.If (expargs S + = expargs + "argument .";ElseS + = expargs + "arguments .";If (numargs S + = numargs + "was passed .";ElseS + = numargs + "were passed .";S
numargs = arguments. length; // obtain the value of the passed parameter.VaR expargs = argtest. length; // obtain the value of the expected parameter.If (expargs S + = expargs + "argument .";ElseS + = expargs + "arguments .";If (numargs S + = numargs + "was passed .";ElseS + = numargs + "were passed .";S + = "\ n"For (I = 0; I S + = "Arg" + I + "=" + arguments + "\ n ";}Return (s); // return the parameter list.}
A code indicating that arguments is not an array (array class) is added here:
Array
the function starts. The following example details these properties:
// Usage of the arguments object.Function argtest (a, B ){VaR I, S = "The argtest function expected ";VaR numargs = arguments. length; // obtain the value of the passed parameter.VaR expargs = argtest. length; // obtain the value of the expected parameter.If (expargs S + = expargs + "argument .";ElseS + = expargs + "arguments .";If (numargs S + = numargs + "was passed .";ElseS + = numargs + "were passed .";S + = "\ n"For (I =
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
arguments object.Function ArgTest (a, B ){Var I, s = "The ArgTest function expected ";Var numargs = arguments. length; // obtain the value of the passed parameter.Var expargs = ArgTest. length; // obtain the value of the expected parameter.If (expargs S + = expargs + "argument .";ElseS + = expargs + "arguments .";If (numargs S + = numargs + "was passed .";ElseS + = numargs + "were passed .";S + = "\ n"For (I = 0; I S + = "Arg" + I + "=" + arguments [I] + "\ n ";}Return (s); // return the parame
these properties:
CopyCode The Code is as follows: // the usage of the arguments object.
Function argtest (a, B ){
VaR I, S = "The argtest function expected ";
VaR numargs = arguments. length; // obtain the value of the passed parameter.
VaR expargs = argtest. length; // obtain the value of the expected parameter.
If (expargs S + = expargs + "argument .";
Else
S + = expargs + "arguments .";
If (numargs S + = numargs + "was passed .";
Else
S + = numargs + "were passed .";
S + = "\ n"
For (I = 0
Before you mention the above concepts, first of all, let's talk about the implied parameters of functions in javascript: arguments
Arguments
The object represents the function being executed and the arguments of the function that called it.
[function.] Arguments[n]
Parameter function: option.The name of the Function object that is currently executing. N: Options. The 0-based parameter value index to pass to the Function object.
Description
Arguments is a hidden object that is created in addition
The first thing to say is the implied parameters of a function in javascript: arguments
Arguments
The object represents the function being executed and the arguments of the function that called it.
[function.] Arguments[n]
Parameter function: option. The name of the Function object that is currently executing. N: Options. The 0-based parameter value index to pass to the Function object.
Description
Arguments is a hidden object that is created in addition to the specified parameters when a functi
Before referring to the above concepts, I would like to start by talking about the implicit parameters of the functions in javascript: argumentsArgumentsThe object represents the function being executed and the parameters of the function that called it.[function.] Arguments[n]Parameter function: option. The name of the Function object that is currently executing. N: Option. The 0-based parameter value index to pass to the Function object.DescriptionArguments is a hidden object that is created in
authoritative guide" gives an example, apply the caller property to write a debug function, to output a stack of traces [function of tracking stack])How to get the name of a function//defining a function method for functions xxx () {}varReg =/function * (\w*) \ (\w*\)/;functionTest () {};varFunname =test.tostring (). Match (reg);if(funname) {Console.log (funname[1]);//Output: Test}//for var xxx = function () {} definition MethodvarTest =function(){};
(Callerdemo. Caller) {VaRA=Callerdemo. Caller. Arguments [0];Alert ();} Else {Alert ("This is a top Function");} }
Function
Handlecaller ()
{Callerdemo ();}
//
Callerdemo ();
//
Handlecaller ("parameter 1", "parameter 2 ");
/** Shows the callee attribute of the function.* Description: arguments. callee: the initial value is the function object being executed. It is used fo
(Arguments.selfvalue);}Running the code you will find that the first alert shows 1, which means that the array object has the Selfvalue property, the value is 1, and when you call the function testaguments, you will find that "undefined" is displayed, stating that the property is not arguments. That is, arguments is not an array object.Second, callerReturns a reference to the function that called the current function.Functionname.callerThe FunctionNa
Concept
Before you mention the above concepts, first of all, let's talk about the implied parameters of functions in javascript: arguments
Arguments
The object represents the function being executed and the arguments of the function that called it.
[function.] Arguments[n]Parameter function: option. The name of the Function object that is currently executing. N: Options. The 0-based parameter value index to pass to the Function object.Description
Arguments is a hidden object that is created in a
arguments, caller, callee, this is a special set of objects that are used in function. Apply () and call () are different ways of calling a function.ArgumentsCan be used to get the actual array of function-passing variables. This variable is particularly suitable for writing "polymorphism" functions, that is, you can do different things depending on the number of incoming arguments.Example One – Add functio
One, call methodCall one of the object's methods and replace the current object with another object (in fact, change the object's internal pointer, that is, change the object's this point).
JS Code
Call ([thisobj[,arg1[, arg2[, [,. argn]]]]
Parameters
Thisobj
Options available. The object that will be used as the current object.
Arg1, Arg2, argn.
Options available. A sequence of method parameters is passed.
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.