JavaScript Function
property:
1. Arguments object
2. Caller
Reference to the function of the pre-calendar function, if it is a top-level code call,
Returns null (firefox returns undefined).
Note: It only makes sense when the code is executed
3. length
Declare the function to be the number of named parameters specified (function definition is, the number of parameters defined)
4. Prototype
An object for constructors, properties and methods defined by this object
All objects created by the constructor are shared.
method:
applay() --> applay(this,[])
call() --> call(this, variable parameters)
toString()
Arguments object for javascript
The Arguments object is only defined in the function body. It is an array of classes (it is an object, not an array, but only has some characteristics of an array).
illustrate:
When a function is called, an Arguments object will be created for the function.
The local variable arguments will automatically initialize and refer to the Arguments object (arguments are references to the Arguments object)
Properties of this object:
1. Callee
Reference to the currently executing function
2. length
Number of parameters passed to function (the number of parameters actually passed to function)
arguments features
The arguments object cannot be created explicitly, and the arguments object is only available when the function starts. The arguments object of a function is not an array, and the way you access a single parameter is accessed the same way you access the elements of an array. Index n is actually one of the parameters of the 0…n property of the arguments object.
In javascript, you do not need to specify parameter names to access them. like:
function hi(){if(arguments[0]=="andy"){ return;}alert(arguments[0]);length attribute of arguments
meaning
Returns the actual number of parameters passed to the function by the calling program.
usage
[function.]arguments.length
Where the optional function parameter is the name of the Function object currently executing.
illustrate
When the Function object starts executing, the script engine initializes the length property of the arguments object to the actual number of parameters passed to the function.
js will not actively judge for you how many parameters you have passed to the function. If you pass more, the excess will not be used. If you pass less, the parameter value that has not been passed is undefined.
So we can use the length property of arguments to detect whether the correct number of actual parameters is used when calling the function, because javascript will not do these things for you.
0...n attribute of arguments
meaning
Returns the actual values of each parameter in an arguments object, the corresponding values are returned by the arguments property of an executing function.
usage
[function.]arguments[[0|1|2|...|n]]
parameter
function
Optional. The name of the Function object currently executing.
0, 1, 2, …, n
Required option. A non-negative integer in the range 0 to n, where 0 represents the first parameter and n represents the last parameter. The value of the last parameter n is arguments.length-1
illustrate
The value returned by the 0 . . n property is the actual value passed to the function being executed. Although it is not actually an array of parameters, you can access the individual parameters that make up the arguments object in the same way as accessing the array elements.
Example
The following example demonstrates the usage of the 0 . . . n attribute of the arguments object
function ArgTest(){ var s = ""; s += "The individual arguments are: " for (n=0; n< arguments.length; n++){ s += ArgTest.arguments[n]; s += " "; } return(s);}print(ArgTest(1, 2, "hello", new Date()));callee property of arguments
meaning
Represents a reference to the function object itself, that is, the body of the specified Function object, which is conducive to realizing the recursion of the nameless function or ensuring the encapsulation of the function.
usage
[function.]arguments.callee
The optional function parameter is the name of the Function object currently executing.
illustrate
The callee property is a member of the arguments object and is only available when the relevant function is being executed.
The initial value of the callee property is the Function object being executed. This allows anonymous recursive functions.
Example:
Use recursion to calculate the sum of natural numbers from 1 to n:
<script> var sum=function(n){ if(1==n) { return 1; } else { return n + arguments.callee(n-1); } } alert(sum(100));</script>Here is an explanation of the function function prototype prototype:
When an object is initialized through a constructor,
The new keyword initializes this object by calling the constructor and passing the new object as the value of this keyword.
At the same time, the new keyword also sets the prototype of this object. The prototype of an object is the value of its constructor's prototype property.
(For example: a = new Date(), the prototype of the a object is Date.prototype)
All functions have a prototype attribute. When this function is [defined], the prototype attribute will be automatically created and initialized.
The initialization value of the prototype attribute is an object, and this object has only one attribute, this attribute is a constructor.
It refers to returning to the constructor associated with the prototype.
The above brief discussion on Functions and Arguments in JavaScript is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.