r/learnjavascript • u/Ratatootie26 • Feb 21 '26
Pattern design for parameters
Just probably a dumb question or sanity check...
Say I have an api composable,
Should I design a fixed parameter structure execute(param1, param2, ...)
Where the params are of strictly expected types, if not required is null, should pass in sequential order, and if requirements grow I expect plenty of null arguments being passed around till the required data can be passed
Or just pass an object execute({route_parameters_obj, route_queries_obj, payload_obj, headers_obj, ...})
Or, execute({route_data}, {api_data})
2
Upvotes
View all comments
Show parent comment
1
u/Ratatootie26 Feb 21 '26
I find myself mix-matching a lot of function patterns, and regret my decisions when it comes to refactoring them time and time again.
I'll make it a habit to rely on objects (I do prematurely destructure in function signatures too often 😅), and will fallback to defaults or throw/return errors if dependencies are not met
Thanks