Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

JScript Function Object

The Function object creates a new function.

Properties: JScript Function Object

JScript Function Object arguments Property

 

An array containing each argument passed to the currently executing function.

JScript Function Object caller Property

A reference to the function that invoked the current function.

JScript Function Object length Property

The number of arguments to the function.

Syntax 1: JScript Function Object

function functionname( [argname1 [, ... argnameN]] )

{

body

}

Syntax 2: JScript Function Object

var functionname = new Function( [argname1, [... argnameN,]] body );

Arguments: JScript Function Object

functionname

The name of the newly created function

argname1...argnameN

An optional list of arguments that the function accepts.

body

A string that contains the block of JScript code to be executed when the function is called.

Remarks: JScript Function Object

Syntax 1 is the standard way to create new functions in JScript. Syntax 2 is an alternative form used to create Function objects explicitly.

The function is a basic data type in JScript. Syntax 1 creates a function value that JScript converts into a Function object when necessary. JScript converts Function objects created by Syntax 2 into function values at the time the function is called.

For example, if you want to create a function that adds the two arguments passed to it, you can do it in either of two ways:

Example 1

function add(x, y)

{

return x + y;

}

Example 2

var add = new Function("x", "y", "return x+y");

In either case, you call the function with a line of code similar to the following:

add(2, 3);

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.