Skip to content

Commit 209f944

Browse files
committed
Changed Function arguments section to include destructuring
1 parent 35f5c5c commit 209f944

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

+12-1
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)