Platform Support
| IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|
| 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Constructors
| Constructor | Action | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|---|
|
Function Constructor(String arg1, arg2, ... argN, String functionBody) : Function
Creates a new instance of the Function object.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Properties
| Property | Action | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|---|
|
invocation arguments : Function
An array-like object corresponding to the arguments passed to a function.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | no | 1.0+ |
|
invocation caller : Function
Specifies the function that invoked the currently executing function.This
property is not part of ECMA-262 Edition 3 standard. It is implemented
at least in SpiderMonkey (the JavaScript engine used in Mozilla) [1] and
JScript.
|
Show Details | 4.0+ | no | 3.0+ | no | no |
|
constructor : Object
Specifies the function that creates the Function prototype.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|
length : Number
Specifies the number of arguments expected by the function.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|
prototype : Object
Creates an instance of a Function class.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Functions
| Method | Action | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|---|
|
apply(Function thisArg, Function argArray) : Object
Allows you to apply a method of another object in the context of a different
object (the calling object).
|
Show Details | 5.5+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
|
call(Function thisArg, Number arg1, arg2, ...) : Object
Allows you to call (execute) a method of another object in the context
of a different object (the calling object).
|
Show Details | 5.5+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
|
toSource() : String
Returns a string representing the source code of the function.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | no | no |
|
toString() : String
Returns a string representing the source code of the function.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
|
valueOf() : String
Returns a string representing the source code of the function.
|
Show Details | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Creating "focus" and "blur" event handlers for a frame
The following example creates onFocus and onBlur event handlers for a frame. This code exists in the same file that contains
the frameset tag. Note that scripting is the only way to create "focus" and
"blur" event handlers for a frame, because you cannot specify
the event handlers in the frame tag.
var frame = frames[0];
frame.onfocus = new Function("document.body.style.backgroundColor = 'white';");
frame.onblur = new Function("document.body.style.backgroundColor = '#bbbbbb';");
Remarks
General
Function objects created with the Function constructor are evaluated each time they are used. This is less efficient
than declaring a function and calling it within your code, because declared
functions are parsed only once.
Specifying arguments with the Function constructor
The following code creates a Function object that takes two arguments.
var multiply = new Function("x", "y", "return x * y");
The arguments x and y are formal argument names that are used in the function body, return x * y.
The preceding code assigns a function to the variable multiply. To call the Function object, you can specify the variable name as if it were a function, as
shown in the following examples.
var theAnswer = multiply(7, 6);
var myAge = 50;
if (myAge >= 39)
myAge = multiply(myAge, .5);
References
Availability
JavaScript 1.0|JScript 1.0|ECMAScript v1
