Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c70968

Browse files
Merge pull request ryanmcdermott#165 from bali182/master
Changed Function arguments section to include destructuring
2 parents 35f5c5c + 209f944 commit 7c70968

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ Since JavaScript allows us to make objects on the fly, without a lot of class
212212
boilerplate, you can use an object if you are finding yourself needing a
213213
lot of arguments.
214214

215+
To make it more obvious what properties does the function expect, use the es6
216+
destructuring syntax. This has a couple of advantages:
217+
218+
1. When someone looks at the function signature, it's immediately clear what
219+
properties are used.
220+
2. Since the function doesn't have the reference to the actual argument, the
221+
user of the function can be sure that no other properties are used by anything
222+
down the call chain.
223+
3. Linters (like eslint) can warn you about unused properties, while this would
224+
be impossible without destructuring.
225+
215226
**Bad:**
216227
```javascript
217228
function createMenu(title, body, buttonText, cancellable) {
@@ -221,7 +232,7 @@ function createMenu(title, body, buttonText, cancellable) {
221232

222233
**Good:**
223234
```javascript
224-
function createMenu(config) {
235+
function createMenu({ title, body, buttonText, cancellable }) {
225236
// ...
226237
}
227238

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /