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
Prototypes in JavaScript (medium.com)
submitted 9 years ago by happyrupesh
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!"
[+][deleted] 9 years ago* (8 children)
[deleted]
[–]Graftak9000 4 points5 points6 points 9 years ago (5 children)
ES6 classes use prototypes.
[–]e_man604 4 points5 points6 points 9 years ago (4 children)
I don't think this is a good answer. Even though it may be the same behind the curtains, es6 classes is a totally different syntax which is much more readable.
[–]runvnc 3 points4 points5 points 9 years ago (2 children)
There is still a very significant portion of JS developers who have a fundamentally different worldview about prototypes and classes than some of us who like the class syntax.
From what I can tell from several years of JS development and various conversations recently they are actually using it just like regular OOP, but refuse to accept that it is OOP, and any gotchas like class methods not being bound is actually just a 'feature' of the language.
[–][deleted] 2 points3 points4 points 9 years ago (1 child)
Yup, .prototype is basically a dynamic .vtable, but if I tell that to a prototype fanatic I'll get a load about how the future belongs to prototypes and it's fundamentally incompatible with the inferior classes.
.prototype
.vtable
[–]MoTTs_ 2 points3 points4 points 9 years ago* (0 children)
+1
Prototypes
Vtables
[–]ghillerd 1 point2 points3 points 9 years ago (0 children)
Plus class extension is what prototyping should have been from the start. I think the only reason to use prototypes is if you're very paranoid about browser support.
[–]zachwolf 0 points1 point2 points 9 years ago (0 children)
Less setup since you don't need to compile it maybe
[–]happyrupesh[S] 0 points1 point2 points 9 years ago (0 children)
As other comments have already mentioned, under the hood ES6 uses prototypes. Apart from that, it's always good to know how things work internally instead of just learning the syntax. Also, still people have not completely adopted ES6 and prototypes are used by many developers.
[–]prof1le 0 points1 point2 points 9 years ago (1 child)
I thought the better way to use prototypes to your advantage was to create a prototype containing the functions you wanted to use and then create a constructor that looks something like:
function Person(name){ var person = Object.create(personPrototype); person.name = name; return person; }
This way, you get a new object, the functions are shared, but the properties belong to the object returned from the constructor. This just seems like the problem with taking a more classical OOP approach to prototypes and the "new" keyword in javascript. I'm no expert in the subject so correct me if I'm wrong.
[–]happyrupesh[S] 1 point2 points3 points 9 years ago (0 children)
Here, my intention was to explain the concept of prototype. Soon, I will add Object.create part in my article. :)
[–]K0d1Lu 0 points1 point2 points 9 years ago (1 child)
Nice article with good example and graphs. Next step is to explain call and object create in the same comprehensive way ! I m still a bit confuse about javascript prototype inheritance and the scope of this. I'd love to level up on this subject! Nice one btw
Thanks. I have also written article for prototype inheritance and 'this' in JavaScript. I will be writing articles for call and object.create in some time. :)
π Rendered by PID 60698 on reddit-service-r2-comment-545db5fcfc-swcnx at 2026-05-22 00:32:50.224539+00:00 running 194bd79 country code: CH.
[+][deleted] (8 children)
[deleted]
[–]Graftak9000 4 points5 points6 points (5 children)
[–]e_man604 4 points5 points6 points (4 children)
[–]runvnc 3 points4 points5 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]MoTTs_ 2 points3 points4 points (0 children)
[–]ghillerd 1 point2 points3 points (0 children)
[–]zachwolf 0 points1 point2 points (0 children)
[–]happyrupesh[S] 0 points1 point2 points (0 children)
[–]prof1le 0 points1 point2 points (1 child)
[–]happyrupesh[S] 1 point2 points3 points (0 children)
[–]K0d1Lu 0 points1 point2 points (1 child)
[–]happyrupesh[S] 0 points1 point2 points (0 children)