mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 06:18:00 -05:00
[guide] Add eslint rules to function declaration and function constructor topics
This commit is contained in:
@@ -588,7 +588,7 @@ Other Style Guides
|
||||
## Functions
|
||||
|
||||
<a name="functions--declarations"></a><a name="7.1"></a>
|
||||
- [7.1](#functions--declarations) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations)
|
||||
- [7.1](#functions--declarations) Use function declarations instead of function expressions. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations)
|
||||
|
||||
> Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions.
|
||||
|
||||
@@ -730,7 +730,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--constructor"></a><a name="7.10"></a>
|
||||
- [7.10](#functions--constructor) Never use the Function constructor to create a new function.
|
||||
- [7.10](#functions--constructor) Never use the Function constructor to create a new function. eslint: [`no-new-func`](http://eslint.org/docs/rules/no-new-func)
|
||||
|
||||
> Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user