@@ -202,26 +202,27 @@ makes testing your function easier. Having more than three leads to a
202
202
combinatorial explosion where you have to test tons of different cases with
203
203
each separate argument.
204
204
205
- Zero arguments is the ideal case. One or two arguments is ok , and three should
206
- be avoided. Anything more than that should be consolidated. Usually, if you have
205
+ One or two arguments is the ideal case , and three should be avoided if possible.
206
+ Anything more than that should be consolidated. Usually, if you have
207
207
more than two arguments then your function is trying to do too much. In cases
208
208
where it's not, most of the time a higher-level object will suffice as an
209
209
argument.
210
210
211
- Since JavaScript allows us to make objects on the fly, without a lot of class
211
+ Since JavaScript allows you to make objects on the fly, without a lot of class
212
212
boilerplate, you can use an object if you are finding yourself needing a
213
213
lot of arguments.
214
214
215
- To make it more obvious what properties does the function expect, use the es6
216
- destructuring syntax. This has a couple of advantages:
215
+ To make it obvious what properties the function expects, you can use the es6
216
+ destructuring syntax. This has a few advantages:
217
217
218
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.
219
+ properties are being used.
220
+ 2 . Destructuring also clones the specified primitive values of the argument
221
+ object passed into the function. This can help prevent side effects. Note:
222
+ objects and arrays that are destructured from the argument object are NOT
223
+ cloned.
224
+ 3 . Linters can warn you about unused properties, which would be impossible
225
+ without destructuring.
225
226
226
227
** Bad:**
227
228
``` javascript
0 commit comments