Java Reference
In-Depth Information
You can also create an anonymous function and assign it to a variable. The following code
demonstrates this approach:
var functionName = function() {
// code here
};
The trailing semicolon is not a typo because this statement is an assignment operation, and all
assignment operations should end with a semicolon.
Functions are objects, and thus they have a constructor. It's possible to create a function using the
Function object's constructor as shown in the following code:
var functionName = new Function("arg1", "arg2", "return arg1 + arg2");
The first arguments to the constructor are the names of the function's parameters—you can add as
many parameters as you need. The last parameter you pass to the constructor is the function's body.
The previous code creates a function that accepts two arguments and returns their sum.
There are very few instances where you will use the Function constructor. It is preferred to define a
function using the standard function statement or by creating an anonymous function and assigning
it to a variable.
Properties
property
introduced
description
JavaScript 1.1
An array containing the parameters passed into the
function.
arguments
JavaScript 1.1
Returns the number of parameters passed into the
function.
arguments.length
JavaScript 1.1
Used to reference the constructor function for the
object.
constructor
JavaScript 1.1
Returns the number of parameters expected by
the function. This differs from arguments.length ,
which returns the number of parameters actually
passed into the function.
length
JavaScript 1.1
Returns the prototype for the object, which can be
used to extend the object's interface.
prototype
Methods
Method
introduced
description
apply(thisObj,
arguments)
JavaScript 1.3
Calls a function or method as if it belonged to thisObj
and passes arguments to the function or method.
arguments must be an array.
Search WWH ::




Custom Search