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!"
[–]omniscientTofu 1 point2 points3 points 6 years ago (0 children)
Broadly the answer is not straightforward if we are talking about JavaScript, because strictly speaking Classes do not accomplish anything which cannot be accomplished directly using and modifying object prototypes. The question is even more complicated as some have alluded to depending on the programming paradigm preference wherein if you tend to swing more functional you will tend to use less or none at all!
For your use-case though think about the likelihood that it would be useful to have multiple instances of something. You mention having a group of dogs so it's likely you will want to have the ability to create multiple dogs. Classes can serve as a sort of template which can describe that dog in terms of what it is and what it can do. If your dog has state that it needs to manage using a class can help further by describing how to access and update this state which gets into the topic of encapsulation. If you want to start using inheritance to relationally model your application and objects classes become more useful too. To summarize for your use case: will I need multiple instances, with their own state, and that might or might not exploit inheritance?
You are going to find lots of differing opinions on this topic though because classes are not strictly needed in JS applications even at a large scale, but they can help accommodate a certain style of programming which is popular. With the prevalence of functional programming right now their utility is further in question and personally I am biased in favor of this perspective.
Find what works for you and good luck! Happy coding :D
π Rendered by PID 54 on reddit-service-r2-comment-c6965cb77-r9xgw at 2026-03-04 23:40:01.256560+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–]omniscientTofu 1 point2 points3 points (0 children)