|-||myFunction = new Function()|
|Object properties:||arity, caller, constructor, length, prototype|
|Object methods:||apply(), call(), toSource(), toString(), valueOf()|
An instance of the class "Function" is created by using the new operator on the Function() constructor. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms.
All properties and functions of the prototype are available as if they were part of the instance.
Many built-in objects are functions. They can be invoked with arguments. Some of these are constructors. They are functions that are intended to be used with the new operator.
Function objects come in four varieties according to how they are implemented. They may be built-in to the interpreter or may be provided as extensions in the script itself. The four types of functions are:
Declared functions in script source text
Anonymous functions build with the Function object constructor
Implementation-supplied functions built into the host environment
Internal functions built into the language
Every built-in function has the Function prototype object as the value returned by its internal Prototype property with the exception of the Function prototype object itself, which would return the Object prototype object.
The prototype for the Function prototype object is the Object prototype object.
If you want to create a function with no name, you can create your own Function object with the new operator. That function would have some script source associated with it and you can then call your function directly. Although it won't have a name, it would appear as if it did in the script source when you call it. However the name it would appear to have is actually the name of the variable containing the reference to it. Since it is an object, two variables can refer to the same object and you could call the same function under two different names. That might happen if you pass the function as an argument in the calling interface to another function. This is a way of implementing call-backs. You might build a comparator like this and pass it to a sort() function.
Creating function objects and referring to them in variables is somewhat like using an eval() function to execute script source that you have built in a string.
// Create a function object var myFunction = new Function("arg1, arg2", "return(arg1 * arg2);"); // And call it document.write(myFunction(5, 10));
|arity||1.2||3.0||4.0||4.0||3.0||, ReadOnly, DontDelete, DontEnum.|
|caller||1.1||1.0||3.0||3.02||3.0||2.0||, ReadOnly, DontEnum., Deprecated|
|length||1.1||1.0||4.0||3.02||2||, ReadOnly, DontDelete, DontEnum., Deprecated|
|prototype||1.1||1.0||3.0||3.02||3.0||2.0||2||ReadOnly, DontDelete, DontEnum.|
ECMA 262 edition 2 - section - 10.1.1
ECMA 262 edition 2 - section - 10.2.4
ECMA 262 edition 2 - section - 13
ECMA 262 edition 2 - section - 15
ECMA 262 edition 2 - section - 15.3
ECMA 262 edition 3 - section - 10.1.1
ECMA 262 edition 3 - section - 13
ECMA 262 edition 3 - section - 15.3