It is common and easy to create function like:
var f = function(){
alert("something");
};
So why is there Function object like:
var f = new Function("alert('something');");
The latter is hard to write/read. I can only come up with one situation in which someone typing some JS code to the webpage and running it. This can also be solved with eval.
Why Function object?
The
Functionobject can be used to dynamically generate functions.Opposed to:
or, using two function expressions:
“This can also be solved with
eval“: