@@ -212,6 +212,17 @@ Since JavaScript allows us to make objects on the fly, without a lot of class
212212boilerplate, you can use an object if you are finding yourself needing a
213213lot 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
217228function 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