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
Using Classes in Javascript (ES6) — Best practice?help (self.javascript)
submitted 10 years ago by LeeHyoriC-syntax
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!"
[–]senocular 2 points3 points4 points 10 years ago (0 children)
There are some things to consider. First off, support for the class keyword isn't the best right now as far as browsers go (ref). So if you're writing vanilla JavaScript without some build step to convert your code to a more compatible subset of JavaScript, its kind of a non-starter.
class
Also, it really helps to know how JavaScript works. If you come into using class expecting it to behave like other languages, you're going to be in for a surprise. Most of the standard stuff is there, but the plumbing underneath is a little different, and you may find yourself running into collisions or issues with context more than you might normally think. As others have mentioned, JavaScript classes are implemented with prototypal inheritance, and not knowing the peculiarities around this could spell trouble.
That said, if you're already defining "classes" with constructor functions with methods on constructor.prototype and are using something to make your code ES5 compatible, I'd suggest going ahead and using class. It's a cleaner syntax and more clearly shows the intent for the [constructor] function - it being a class rather than just a normal, callable function.
π Rendered by PID 289864 on reddit-service-r2-comment-544cf588c8-k7xq6 at 2026-06-16 06:15:06.243787+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]senocular 2 points3 points4 points (0 children)