today. But I have never seen the actual implementation which actually uses the function
constructor. So I would like to ask, is there any circumstance that unlike using function ()
declaration, can we get benefits using the function
constructor?
var func = What is the hidden difference between the new function ("x", "y", "return x * y;") ; // pass reference by string
function ():
var func = function (x, y) {return X * y; }
thanks
function constructor eval
, which should be avoided normally (it is considered to be slow and unsafe) is not really useful to use the function controller on the function controller, unless you want to create a function from the dynamic components, Which is very rare. There are legitimate uses of this form, although most of the time it is used unnecessarily, which is why it is seen below and generally left.
In addition, the functions created with the function constructor will not keep the context of those environment, which they were defined in (closing). When executed, they will pull those variables directly from the global scope.
var f, a; (Function () {var a = 123; f = new function ("return");}) (); F (); // unspecified one = "global" F (); // "Global"
While regular functions are in the context of the environment in which they were defined:
var f; (Function () {var a = 123; f = function ()} {return a;}}) (); F (); // 123
Comments
Post a Comment