Function() (Constructor)

A Function object constructor.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 1.0
Internet Explorer - 3.02
Netscape - 3.0
JavaScript syntax:-new Function()
-new Function(someArguments)
Argument list:someArgumentsSome formal parameters and a block of script source

The function constructor can be called with the new operator or as a function.

The initial value of Function.prototype.constructor is the built-in Function constructor.

The arguments supplied to the Function() constructor are all assumed to be parameters apart from the last one which is taken to be the body Source Script Text. If there is only one argument, then that is taken to be the body of the function.

If there are no arguments, an empty function is created.

Note that it is permissible but not necessary to have a separate argument for each formal parameter. All three of these examples produce exactly the same result:

A prototype property is automatically created in case the function object is used as a constructor at some future time.

The function constructor will always create top level functions without static scoping. This is a little different to the behavior of a function literal, available in JavaScript version 1.2 onwards.

See also:Constructor function, constructor property, Function call, Function object, Function.prototype, Global object, new, Object constant

Cross-references:

ECMA 262 edition 2 - section - 15.1.3.2

ECMA 262 edition 2 - section - 15.3.1

ECMA 262 edition 2 - section - 15.3.4.1

ECMA 262 edition 3 - section - 15.3.2