What they wanted to highlight is that the JS parser needs to its work every single time the Function
constructor is called - basically just the obvious. There is no caching of the passed code string involved.
This is relevant [only] when compared with closures. Suppose we have these two functions:
function makeAlerterParse(string) {
return Function("alert("+JSON.stringify(string)+");");
}
function makeAlerterClosure(string) {
return function alerter() { alert(string); };
}
Both function declarations will be parsed when the script is loaded - no surprises. However, in the closure also the alerter
function expression is parsed already. Let's make some alerters:
var alerter1 = makeAlerterParser("1"); // Here the parser will be invoked
alerter1(); // no parsing, the function is instantiated already and
alerter1(); // can be interpreted again and again.
var alerter2 = makeAlerterClosure("2"); // Here, no parser invocation -
alerter2(); // it's just a closure whose code was already known
alerter2(); // but that has now a special scope containing the "2" string
Still no surprise? Good, then you have already understood everything. The warning is only that an explicit invocation like
for (var fnarr=[], i=0; i<100; i++)
fnarr[i] = makeAlerterParse(i);
will really be 100 invocations of the JS parser, while the closure version comes for free.