1.var f = new Function("a", "b", "return a+b")
2.var f2 = Function("a", "b", "return a+b")
f
and f2
both are a anonymous function. f(1,2)
and f2(1,2)
both returns 3
. So is there any actual internal difference between the two?
Does Function
internally return a function object? Difference from using the Function
as constructornew Function(...)
?
From the ECMAScript 5.1 specs:
When Function is called as a function rather than as a constructor, it creates and initialises a new Function object. Thus the function call Function(…) is equivalent to the object creation expression new Function(…) with the same arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With