Skip to content

Commit

Permalink
Merge pull request airbnb#347 from airbnb/goatslacker-patch-1
Browse files Browse the repository at this point in the history
Amend the arrow function rules
  • Loading branch information
goatslacker committed May 18, 2015
2 parents 7ac20d6 + cbcb09f commit 5cbb666
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,32 +590,20 @@
});
```
- [8.2](#8.2) <a name='8.2'></a> If the function body fits on one line, feel free to omit the braces and use implicit return. Otherwise, add the braces and use a `return` statement.
- [8.2](#8.2) <a name='8.2'></a> If the function body fits on one line and there is only a single argument, feel free to omit the braces and parentheses, and use the implicit return. Otherwise, add the parentheses, braces, and use a `return` statement.
> Why? Syntactic sugar. It reads well when multiple functions are chained together.
> Why not? If you plan on returning an object.
```javascript
// good
[1, 2, 3].map((x) => x * x);

// good
[1, 2, 3].map((x) => {
return { number: x };
});
```
- [8.3](#8.3) <a name='8.3'></a> Always use parentheses around the arguments. Omitting the parentheses makes the functions less readable and only works for single arguments.
> Why? These declarations read better with parentheses. They are also required when you have multiple parameters so this enforces consistency.
```javascript
// bad
[1, 2, 3].map(x => x * x);

// good
[1, 2, 3].map((x) => x * x);
[1, 2, 3].reduce((total, n) => {
return total + n;
}, 0);
```
**[⬆ back to top](#table-of-contents)**
Expand Down

0 comments on commit 5cbb666

Please sign in to comment.