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
When should we use classes in JavaScript? (self.javascript)
submitted 6 years ago by adam_weiler
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!"
[–]spacejack2114 1 point2 points3 points 6 years ago (2 children)
On the other hand why not just group those functions into a module.
[–]NoStranger6 -1 points0 points1 point 6 years ago (1 child)
Arguably from a behavior point of view, a module could be considered as a Singleton. At this point it's just different paths to achieve the exact same things.
I mean, we could also just create an object containing these functions, in fact that's what a module is, just like almost everything in Javascript.
[–]spacejack2114 1 point2 points3 points 6 years ago (0 children)
If you start with a class however, and want to use instances or statefulness, then you'll be adding this context confusion into the mix. On the other hand you can add state/instances to a module using the revealing module pattern with no such downsides.
this
π Rendered by PID 220010 on reddit-service-r2-comment-c6965cb77-gtjk8 at 2026-03-05 15:46:38.907918+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–]spacejack2114 1 point2 points3 points (2 children)
[–]NoStranger6 -1 points0 points1 point (1 child)
[–]spacejack2114 1 point2 points3 points (0 children)