User Tools

Site Tools


Function

ECMASCript Function prototype object.

More...

Inherits :

Properties

Constructors

ECMAScript
Function ( String p1, String p2, …, String pn, String body )

Methods

ECMAScript
Objectapply ( Object thisArg, Array argArray )
voidbind ( Object thisArg, … )
Objectcall ( Object thisArg, … )
StringtoString ()

Detailed Description

Todo

Descriptions

Example:

var oMyFunction = function()
{
}

Properties


Array : arguments

An array of the arguments passed to the function. (Read Only)

Example:

function sum(){
	var nTotal = 0;
	for( var i = 0; i < arguments.length; i++ ){
		nTotal += arguments[ i ];
	}
	return nTotal;
}
var nSum = sum( 2, 3, 4, 5 );
// nSum: 14

Number : length

Holds the “typical” number of arguments expected by the function.

Constructors


Function( String p1, String p2, …, String pn, String body )

Default Constructor. Creates a new function. All arguments are optional - zero or more argument names may be specified, the last argument, if any, is always used as the body of the function.

Parameter(s):

  • p1 - The name of the first parameter.
  • p2 - The name of the second parameter.
  • pn - The name of the last parameter.
  • body - The text of the executable code of the function.

Methods


Object : apply( Object thisArg, Array argArray )

Performs a function call with a given this value and argArray arguments.

Note:

  • The syntax of this function is almost identical to that of call(). A fundamental difference, however, is that call() accepts optional arguments to the Function itself, while this function accepts an array of arguments.

Parameter(s):

  • thisArg - The object that serves as the this value for the function call. If undefined, or not provided, the global object is used.
  • argArray - An optional array of arguments for the function; if not provided, the function is called without any arguments.

Return Value:

  • The return value of the function.

void : bind( Object thisArg, … )

Creates a new function that, when called, has its this keyword set to thisArg, with the given sequence of arguments preceding any provided when the new function is called.

Parameter(s):

  • thisArg - The object that serves as the this value for the function call. If undefined, or not provided, the global object is used.
  • - Optional argument(s) to prepend to arguments provided to the bound function when invoking the function being bound.

Object : call( Object thisArg, … )

Performs a function call with a given this value and optional arguments.

Note:

  • The syntax of this function is almost identical to that of apply(). A fundamental difference, however, is that apply() accepts an array of arguments, while this function accepts optional arguments to the function itself.

Parameter(s):

  • thisArg - The Object that serves as the this value for the function call. If undefined, or not provided, the global object is used.
  • - Optional argument(s) for the function.

Return Value:

  • The return value of the function.

String : toString()

Return Value:

  • A string representation of the function.