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:
new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a, b", "c", "return a+b+c")
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.
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
Prev | Home | Next |
Function object | Up | Function() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |