es6: shorten destructuring example

This commit is contained in:
Rico Sta. Cruz 2018-03-17 13:33:08 +08:00
parent 6ebd835202
commit 6c21eb39c0
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 5 additions and 5 deletions

10
es6.md
View File

@ -232,18 +232,18 @@ greet({ name: 'Larry', greeting: 'Ahoy' })
Destructuring of objects and arrays can be also be done in function arguments. Destructuring of objects and arrays can be also be done in function arguments.
### Default values in destructured function arguments ### Default values
```js ```js
function greet({ name = 'Rauno', greeting = 'Hello' } = {}) { function greet({ name = 'Rauno' } = {}) {
console.log(`${greeting}, ${name}!`); console.log(`Hi ${name}!`);
} }
``` ```
{: data-line="1"} {: data-line="1"}
```js ```js
greet() // Hello, Rauno! greet() // Hi Rauno!
greet({ name: 'Larry' }) // Hello, Larry! greet({ name: 'Larry' }) // Hi Larry!
``` ```
### Reassigning keys ### Reassigning keys