mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 19:27:57 -05:00
[guide] Add clarification to arrow functions
Clarify and correct explanation — to be consistent with section 7.1 (use named function expressions).
This commit is contained in:
committed by
Jordan Harband
parent
67e34433e4
commit
39cf84f43b
@@ -912,11 +912,11 @@ Other Style Guides
|
||||
## Arrow Functions
|
||||
|
||||
<a name="arrows--use-them"></a><a name="8.1"></a>
|
||||
- [8.1](#arrows--use-them) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions)
|
||||
- [8.1](#arrows--use-them) When you must use an anonymous function (as when passing an inline callback), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions)
|
||||
|
||||
> Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax.
|
||||
|
||||
> Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.
|
||||
> Why not? If you have a fairly complicated function, you might move that logic out into its own named function expression.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
|
||||
Reference in New Issue
Block a user