Skip to content

Commit

Permalink
Merge pull request ryanmcdermott#165 from bali182/master
Browse files Browse the repository at this point in the history
Changed Function arguments section to include destructuring
  • Loading branch information
ryanmcdermott authored Jan 21, 2017
2 parents 35f5c5c + 209f944 commit 7c70968
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ Since JavaScript allows us to make objects on the fly, without a lot of class
boilerplate, you can use an object if you are finding yourself needing a
lot of arguments.

To make it more obvious what properties does the function expect, use the es6
destructuring syntax. This has a couple of advantages:

1. When someone looks at the function signature, it's immediately clear what
properties are used.
2. Since the function doesn't have the reference to the actual argument, the
user of the function can be sure that no other properties are used by anything
down the call chain.
3. Linters (like eslint) can warn you about unused properties, while this would
be impossible without destructuring.

**Bad:**
```javascript
function createMenu(title, body, buttonText, cancellable) {
Expand All @@ -221,7 +232,7 @@ function createMenu(title, body, buttonText, cancellable) {

**Good:**
```javascript
function createMenu(config) {
function createMenu({ title, body, buttonText, cancellable }) {
// ...
}
Expand Down

0 comments on commit 7c70968

Please sign in to comment.