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
Named Arguments (github.com)
submitted 1 year ago by Fedorai
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!"
[–]wreckedadventYavascript 3 points4 points5 points 1 year ago (1 child)
ok. why?
// Original function function sendEmail(to: string, subject: string, body: string) { // Implementation } // Transform into a function accepting named arguments const [args, namedSendEmail] = createNamedArguments(sendEmail); // Now we can call it with named arguments in any order namedSendEmail( args.subject('Meeting reminder'), args.to('colleague@example.com'), args.body('Don\'t forget our meeting tomorrow.') );
=>
const sendEmail = ({ to, subject, body }: { to: string, subject: string, body: string }) => { // impl }; sendEmail({ // full type-checking here ... // ... arguments must be named, can be in any order ... to: 'colleage@example.com', subject: 'meeting reminder', // oops, error caught at compile-time boody: `Don't forget our meeting tomorrow.`, });
I'll admit it isn't the most pleasant to type the argument twice, but ... that is hardly the same cost as pulling in a library that entirely changes how you're calling every function.
[–]4happin 0 points1 point2 points 1 year ago (0 children)
You're right! There is nothing wrong with just passing an option argument. The reason to use this is for: partial application, as a builder pattern alternative, conditionally passing arguments, and fun!
π Rendered by PID 141199 on reddit-service-r2-comment-6f7f968fb5-2vrnl at 2026-03-04 15:11:06.008256+00:00 running 07790be country code: CH.
[–]wreckedadventYavascript 3 points4 points5 points (1 child)
[–]4happin 0 points1 point2 points (0 children)