Skip to content

Commit b2559f4

Browse files
authored
Update article.md
1 parent 0d81f75 commit b2559f4

File tree

1 file changed

+8
-6
lines changed
  • 1-js/06-advanced-functions/07-new-function

1 file changed

+8
-6
lines changed

1-js/06-advanced-functions/07-new-function/article.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ There's one more way to create a function. It's rarely used, but sometimes there
1010
The syntax for creating a function:
1111

1212
```js
13-
let func = new Function('a', 'b', 'return a + b');
13+
let func = new Function ([arg1[, arg2[, ...argN]],] functionBody)
1414
```
1515

16-
All arguments of `new Function` are strings. Parameters go first, and the body is the last.
16+
In other words, function parameters (or, more precise, names for them) go first, and the body is the last. All arguments are strings.
1717

18-
For instance:
18+
That's easy to understand by example.
19+
20+
For instance, here's a function with two arguments:
1921

2022
```js run
21-
let sum = new Function('arg1', 'arg2', 'return arg1 + arg2');
23+
let sum = new Function('a', 'b', 'return a + b');
2224

2325
alert( sum(1, 2) ); // 3
2426
```
2527

26-
If there are no arguments, then there will be only body:
28+
If there are no arguments, then there's only one single argument, function body:
2729

2830
```js run
2931
let sayHi = new Function('alert("Hello")');
@@ -136,4 +138,4 @@ new Function('a,b', ' return a + b; '); // comma-separated
136138
new Function('a , b', ' return a + b; '); // comma-separated with spaces
137139
```
138140

139-
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.
141+
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.

0 commit comments

Comments
 (0)