Update es6.md (#709)

* Update es6.md

Add edge case of implicitly returned object, since the notation is a little different.

* Update es6.md: fix typo
This commit is contained in:
Hannes Leutloff 2018-11-16 20:28:50 +01:00 committed by chad d
parent 41c619d50d
commit 05bca6d01c
1 changed files with 5 additions and 1 deletions

6
es6.md
View File

@ -385,8 +385,12 @@ readFile('text.txt', (err, data) => {
numbers.map(n => n * 2)
// No curly braces = implicit return
// Same as: numbers.map(function (n) { return n * 2 })
numbers.map(n => ({
result: n * 2
})
// Implicitly returning objects requires parentheses around the object
```
{: data-line="1"}
{: data-line="1,4,5,6"}
Like functions but with `this` preserved.
See: [Fat arrows](https://babeljs.io/learn-es2015/#arrows-and-lexical-this)