0% found this document useful (0 votes)
41 views

Syntax: Parameters Arg1, Arg2, ... Argn

The Function constructor creates a new Function object dynamically at runtime. It allows specifying function arguments and body as strings. Functions created with the Function constructor are less efficient than regular function declarations since they are parsed when created rather than with the rest of the code. The Function constructor can be called as a regular function or as a constructor, and Function objects inherit properties and methods through Function.prototype.

Uploaded by

nipu90
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Syntax: Parameters Arg1, Arg2, ... Argn

The Function constructor creates a new Function object dynamically at runtime. It allows specifying function arguments and body as strings. Functions created with the Function constructor are less efficient than regular function declarations since they are parsed when created rather than with the rest of the code. The Function constructor can be called as a regular function or as a constructor, and Function objects inherit properties and methods through Function.prototype.

Uploaded by

nipu90
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

The Function constructor creates a new Function object.

Calling the
constructor directly can create functions dynamically, but suffers
from security and performance issues similar to eval.
Every JavaScript function is actually a Function object.
Syntax
new Function ([arg1[, arg2[, ...argN]],] functionBody)

Parameters
arg1, arg2, ... argN
Names to be used by the function as formal argument names. Each
must be a string that corresponds to a valid JavaScript identifier or a
list of such strings separated with a comma; for example "x",
"theValue", or "a,b".
functionBody
A string containing the JavaScript statements comprising the function
definition.

Description
Function objects created with the Function constructor are parsed when
the function is created. This is less efficient than declaring a function with
a function expression or function statement and calling it within your
code, because such functions are parsed with the rest of the code.
All arguments passed to the function are treated as the names of the
identifiers of the parameters in the function to be created, in the order in
which they are passed.

Invoking the Function constructor as a function (without using


the new operator) has the same effect as invoking it as a constructor.
Properties and Methods of Function
The global Function object has no methods or properties of its own.
However, since it is a function itself, it does inherit some methods and
properties through the prototype chain from Function.prototype.

You might also like