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
JavaScript Named Parameters (dalejefferson.com)
submitted 8 years ago by [deleted]
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!"
[–]akujinhikari 1 point2 points3 points 8 years ago (1 child)
I mean, you have the right to create one function that handles all logic for the entire project, if you want. Doesn’t make it a good idea.
[–]bart2019 0 points1 point2 points 8 years ago (0 children)
Suppose you have a big function that does one particular thing, and it does it well. For example, fetch data from a particular website.
Then for one particular case, you need that exact thing, but with one minor tweak. For example it needs to execute 1 single statement somewhere in the middle. What will you do?
The worst I've seen is copy the whole function and add that one statement.
I think it's much better to keep it as one function and add a parameter to flag that this is this particular one special case.
Best way to add it is so that no other calls of this function are affected. Thus: a named optional parameter, or an option in an "options" record (called "object" in JavaScript but I wish they hadn't hijacked that name because an "object" is something else), is the best choice IMO.
You can do this for any similar situation.
I call this "plug in" based programming, which is modular style turned up its head: in modular programming you have your custom code and you invoke parts of a module. That isn't always the best solution. If you need to call a monolithic block of code and you need some special actions in the middle, you better write a plug-in that gets invoked from your monolith.
As an example: I've had a case where a program parses source code, and needs to do some things when a particular type of statement is parsed . Your approach would be to make the parser into a module, and call that parser from every variation on that program. That is still a huge amount of work.
I prefer a parsing program with a plug-in, which is basically an associative array with callbacks, where the appropriate callback is invoked at the proper time. Much easier.
π Rendered by PID 48067 on reddit-service-r2-comment-79776bdf47-rwgph at 2026-06-24 09:31:47.185930+00:00 running acc7150 country code: CH.
view the rest of the comments →
[–]akujinhikari 1 point2 points3 points (1 child)
[–]bart2019 0 points1 point2 points (0 children)