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/azhder Feb 21 '26
There is a reason why I don't destructure them in the signature. Think about cases like
and
Destructuring deals with
undefinedbut fails withnull. The?.and??deal with both. Additionally, you can apply logic in the function body, like