[guide] Fix inconsistency in function expression rules.

This commit is contained in:
Andrew Smith
2016-10-25 14:47:25 -07:00
committed by Jordan Harband
parent 153c02b36c
commit 3ab19f07f4

View File

@@ -576,7 +576,7 @@ Other Style Guides
<a name="functions--declarations"></a><a name="7.1"></a>
- [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations)
> Why? Function declarations are hoisted, which means that its easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a functions definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps its time to extract it to its own module! Dont forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack.
> Why? Function declarations are hoisted, which means that its easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a functions definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps its time to extract it to its own module! Dont forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack. ([Discussion](https://github.com/airbnb/javascript/issues/794))
```javascript
// bad