JavaScript has a Function
constructor which produces an anonymous function:
new Function()
When passing a function as an argument to Function
, I get a syntax error:
new Function(function(){})
produces
SyntaxError: Unexpected token (
However, when I pass a number, all is fine:
new Function(10)
Why do I get a syntax error when passing a function to Function
?