Design Patterns · Junior · Question 43 of 75
A function takes 7 arguments. Which refactoring is usually appropriate?
- ✓Correct answer: Pass an options object with named fields
- 2Split the call into 7 calls with one argument each
- 3Move the arguments into global variables
Explanation
A long parameter list is a "code smell": it's easy to mix up the order. An object with destructuring ({ id, title, onSave }) is self-documenting and allows default values. Sometimes it's a sign that the function does too much.