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?
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function
Considering all but the last arguments are argument names, I wouldn’t expect anything other than a string to work.
I would imagine the syntax error is because of the way the JS engine you’re using internally tries to convert the function to a string. I’m actually surprised it doesn’t choke on the 10.
Also, I suspect you’re doing this just out of curiosity, but if you’re not, I suggest you not use
Functionin code you can control. There’s not really a reason to use Function unless you need to take a string and make a function out of it at run time.