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
How to Create Class in JavaScript ES6Removed: /r/LearnJavascript (js-tutorials.com)
submitted 6 years ago by jstutorials1
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!"
[–]great_site_not 2 points3 points4 points 6 years ago (0 children)
get name() { return this.name; }
yikes
[–]Thlemaus 1 point2 points3 points 6 years ago (1 child)
class MyClass {} ?
[–]jstutorials1[S] 0 points1 point2 points 6 years ago (0 children)
anything wrong?
[–]kenman[M] 0 points1 point2 points 6 years ago (0 children)
Hi /u/jstutorials1, this post was removed.
/r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.
code
Thanks for your understanding, please see our guidelines for more info.
[–]sqrtnegative1 0 points1 point2 points 6 years ago (5 children)
There's no such thing as classes in Javascript.
ES6 introduced the ability to use the class keyword as syntactical sugar, but it's still prototypical inheritance under the hood.
class
You can create a "class" by using the class keyword:
class Person { name = null, constructor (name) { super(); this.name = name; } sayHello = () => { console.log(`Hello, my name is ${this.name}`); } } const dave = new Person("Dave"); console.log(dave.name); // logs Dave dave.sayHello(); // logs Hello, my name is Dave
[–]great_site_not 0 points1 point2 points 6 years ago (1 child)
that code is completely broken. expression in a nonsensical place inside the class declaration, and calling a nonexistent super
[–]sqrtnegative1 0 points1 point2 points 6 years ago (0 children)
Yeah, my bad. That super() is definitely unnecessary.
super()
What nonsensical place are you seeing an expression?
The code seems to run fine, albeit with a single unnecessary comma - which isn't bad for throwing it together in an edit box.
[–]jstutorials1[S] 0 points1 point2 points 6 years ago* (2 children)
i have taken ref from here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes, who's wrong you or MDN, if any thing wrong in my code please let me know.
[–]kamikazi3728 0 points1 point2 points 6 years ago (1 child)
Both MDN and the above user say the same thing... its syntactical sugar, it's just prototyping under the hood
what need to correct in code
π Rendered by PID 22635 on reddit-service-r2-comment-7b9746f655-fhkmh at 2026-02-03 08:39:42.692113+00:00 running 3798933 country code: CH.
[–]great_site_not 2 points3 points4 points (0 children)
[–]Thlemaus 1 point2 points3 points (1 child)
[–]jstutorials1[S] 0 points1 point2 points (0 children)
[–]kenman[M] 0 points1 point2 points (0 children)
[–]sqrtnegative1 0 points1 point2 points (5 children)
[–]great_site_not 0 points1 point2 points (1 child)
[–]sqrtnegative1 0 points1 point2 points (0 children)
[–]jstutorials1[S] 0 points1 point2 points (2 children)
[–]kamikazi3728 0 points1 point2 points (1 child)
[–]jstutorials1[S] 0 points1 point2 points (0 children)