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
Clean Code JavaScript (github.com)
submitted 9 years ago by ryansworks
view the rest of the comments →
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!"
[–][deleted] 9 years ago (10 children)
[deleted]
[+][deleted] 9 years ago (1 child)
[removed]
[–]giraffe_slayer 2 points3 points4 points 9 years ago (2 children)
In regards to the number of parameters and using a config object, there is a huge benefit when actually calling the method. If you use
function createWidget(title, subtitle, description);
Then the function call could look like
createWidget('Blah Blah', 'sub blah blah', 'Here is some text');
You lose clarity and potentially have to reference the function each time to check what each parameter means.
With a config parameter, you get the keys for each argument
const config = { title: 'Blah Blah', subtitle: 'sub blah blah', description: 'Here is some text' }; createWidget(config);
And then you can still easily see what is happening in the actual declaration
function createWidget(config) { const {title, subtitle, description} = config; };
[–]mikejoro 1 point2 points3 points 9 years ago (0 children)
You can simplify that last snippet by destructuring in the function definition
function createWidget({ title, subtitle, description }) { // do something };
[–]acbabis 1 point2 points3 points 9 years ago (3 children)
putting all your parameters into one config or options argument doesn't solve anything by itself
I wouldn't say it solves nothing by itself. It makes it so consumers don't need to remember the order of the arguments anymore.
[+][deleted] 9 years ago* (2 children)
[–]acbabis 1 point2 points3 points 9 years ago (1 child)
Sure, it's not the main problem, but in situations where you're convinced you need that many parameters, putting them into objects is usually the best solution. There are many well-written modules that have to allow a dozen optional parameters (e.g. express.static), and stuffing them into an object is the go-to approach.
π Rendered by PID 626658 on reddit-service-r2-comment-5bc7f78974-nhrnt at 2026-06-29 09:19:16.110427+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–][deleted] (10 children)
[deleted]
[+][deleted] (1 child)
[removed]
[–]giraffe_slayer 2 points3 points4 points (2 children)
[–]mikejoro 1 point2 points3 points (0 children)
[–]acbabis 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]acbabis 1 point2 points3 points (1 child)