5

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(...)?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375

1 Answers1

7

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.

Korikulum
  • 2,529
  • 21
  • 25