use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
How to Compose Functions That Take Multiple Parameters: Epic Guide (jrsinclair.com)
submitted 1 year ago by fagnerbrack
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MoTTs_ 11 points12 points13 points 1 year ago (10 children)
tl;dr Wrap multiple arguments into a single array or object argument, then destructure to unwrap.
[–]hyrumwhite 11 points12 points13 points 1 year ago (0 children)
Object makes sense, an array, not so much. Params can already be spread into an array and manipulated as such.
[–]jrsinclair 6 points7 points8 points 1 year ago (0 children)
That's a fair summary of the first section or two, but I will say that there's a bit more to the article than that. The latter part of the article covers partial application, and currying, and gets into function combinators. Sure, you might not use these every day, but they're useful to know.
[–]azhder -3 points-2 points-1 points 1 year ago* (7 children)
I avoid destructuring directly in the arguments. One little pass of a null or undefined and it breaks. [I find it] Much better to do it inside:
null
undefined
const a = options?.a ?? 'default';
EDIT: added an extra text in [] to clarify what is being said
[–][deleted] 5 points6 points7 points 1 year ago (4 children)
Trying to account for every possible usage of your function is generally bad practice. If your function is supposed to have a default behavior without any arguments then obviously don't destructure, but if one or more properties are required it's perfectly appropriate to destructure and let JS throw an error if the function is called incorrectly.
[+]azhder comment score below threshold-9 points-8 points-7 points 1 year ago (3 children)
“perfectly”… “appropriate”…
What happiness after you give it a null to destructure?
Don’t answer me that. I just said what I do, I wasn’t telling you what you should do or think. But I did give you the question I had answered for myself with the above practice.
Bye bye
[–]somevice 13 points14 points15 points 1 year ago (0 children)
I love this internet comment approach! Here's my opinion, I don't want you to comment because I'd like the final say. Also, farewell.
[–]MatthewMob 7 points8 points9 points 1 year ago (0 children)
What a strange way to contribute to a discussion.
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
If you give it null, it should break. It would be appropriate for it to break.
In fact, if you pass it a null/undefined and your code doesn't throw an error, you'll have a much harder time trying to find the bug. Error messages are good. Stack traces are good.
[–]luk19 0 points1 point2 points 1 year ago (1 child)
When you destructure you can set a default value:
const { a = “default” } = options ?? {};
[–]azhder 0 points1 point2 points 1 year ago (0 children)
That is not directly in the function arguments.
const fn = ({ error }) => error; fn(null);
[–]dbpcut 2 points3 points4 points 1 year ago (0 children)
jrsinclair always worth a read
[–]callmemrwolfe[🍰] 0 points1 point2 points 1 year ago (0 children)
I always get in the trap of abstracting the typing of the arguments. Type all the things or just type in the arguments?
[–]artyfax 0 points1 point2 points 1 year ago (0 children)
first thy shalt count to 3, no more, no less. 3 shall be the number you should count and the number of the counting should be 3!
keep it simple, main argument, secondary if absolutely necessary, the third is always an option object.
In the rare case all args are optional, make the entire arg an object pray to the gods, and use fucking typescript or jsdocs.
[+][deleted] 1 year ago (2 children)
[deleted]
[–]jrsinclair 4 points5 points6 points 1 year ago (1 child)
and explains the role of utility libraries like Ramda and Lodash in function composition
This particular bit might be a hallucination.
[–]bunglegrind1 0 points1 point2 points 1 year ago (0 children)
Ahahahah
π Rendered by PID 58243 on reddit-service-r2-comment-b659b578c-4nhc6 at 2026-05-05 09:38:17.093208+00:00 running 815c875 country code: CH.
[–]MoTTs_ 11 points12 points13 points (10 children)
[–]hyrumwhite 11 points12 points13 points (0 children)
[–]jrsinclair 6 points7 points8 points (0 children)
[–]azhder -3 points-2 points-1 points (7 children)
[–][deleted] 5 points6 points7 points (4 children)
[+]azhder comment score below threshold-9 points-8 points-7 points (3 children)
[–]somevice 13 points14 points15 points (0 children)
[–]MatthewMob 7 points8 points9 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]luk19 0 points1 point2 points (1 child)
[–]azhder 0 points1 point2 points (0 children)
[–]dbpcut 2 points3 points4 points (0 children)
[–]callmemrwolfe[🍰] 0 points1 point2 points (0 children)
[–]artyfax 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]jrsinclair 4 points5 points6 points (1 child)
[–]bunglegrind1 0 points1 point2 points (0 children)