. .
:
let func = new Function ([arg1, arg2, ...argN], functionBody);
arg1...argN functionBody .
. :
let sum = new Function('a', 'b', 'return a + b');
alert( sum(1, 2) ); // 3
:
let sayHi = new Function('alert("")');
sayHi(); //
() .
.
new Function . :
let str = ... ...
let func = new Function(str);
func();
.
[[Environment]] . (lexical environment) ( ).
new Function [[Environment]] .
.
function getFunc() {
let value = "";
let func = new Function('alert(value)');
return func;
}
getFunc()(); // error: value is not defined
:
function getFunc() {
let value = "";
let func = function() { alert(value); };
return func;
}
getFunc()(); // "test", getFunc
new Function .
. ( ) . .
.
minifier . .
let userName (minifier) let a ( ) . . . . .
new Function userName .
new Function , .
.
new Function .
:
let func = new Function ([arg1, arg2, ...argN], functionBody);
.
:
new Function('a', 'b', 'return a + b'); //
new Function('a,b', 'return a + b'); //
new Function('a , b', 'return a + b'); // -
new Function [[Environment]] . . .
<code><pre>. (plnkr jsbin codepen)