diff --git a/1-js/06-advanced-functions/07-new-function/article.md b/1-js/06-advanced-functions/07-new-function/article.md index b44da634..73805745 100644 --- a/1-js/06-advanced-functions/07-new-function/article.md +++ b/1-js/06-advanced-functions/07-new-function/article.md @@ -10,20 +10,22 @@ There's one more way to create a function. It's rarely used, but sometimes there The syntax for creating a function: ```js -let func = new Function('a', 'b', 'return a + b'); +let func = new Function ([arg1[, arg2[, ...argN]],] functionBody) ``` -All arguments of `new Function` are strings. Parameters go first, and the body is the last. +In other words, function parameters (or, more precise, names for them) go first, and the body is the last. All arguments are strings. -For instance: +That's easy to understand by example. + +For instance, here's a function with two arguments: ```js run -let sum = new Function('arg1', 'arg2', 'return arg1 + arg2'); +let sum = new Function('a', 'b', 'return a + b'); alert( sum(1, 2) ); // 3 ``` -If there are no arguments, then there will be only body: +If there are no arguments, then there's only one single argument, function body: ```js run let sayHi = new Function('alert("Hello")'); @@ -136,4 +138,4 @@ new Function('a,b', ' return a + b; '); // comma-separated new Function('a , b', ' return a + b; '); // comma-separated with spaces ``` -Functions created with `new Function`, have `[[Environment]]` referencing the global Lexical Environment, not the outer one. Hence, they can not use outer variables. But that's actually good, because it saves us from errors. Explicit parameters passing is a much better thing architecturally and has no problems with minifiers. \ No newline at end of file +Functions created with `new Function`, have `[[Environment]]` referencing the global Lexical Environment, not the outer one. Hence, they can not use outer variables. But that's actually good, because it saves us from errors. Explicit parameters passing is a much better thing architecturally and has no problems with minifiers.