How to Use Function "Constructors"

Functions can be created using a "function" statement or the Function() constructor. Dynamic functions are created when defining functions with the "new" operator and Function() constructor. Constructors not only create new objects but also specify the behaviors and properties of those objects.

Constructor

Function()

Creates a new Function object. Calling the constructor directly can create functions dynamically but suffers from security and similar (but far less significant) performance issues to eval(). However, unlike eval(), the Function constructor creates functions that execute in the global scope only.