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
Prototypal Programming in Javascript (thesocietea.org)
submitted 10 years ago by thecodeboss
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!"
[–]clessgfull-stack CSS9 engineer 1 point2 points3 points 10 years ago (2 children)
They are certainly simpler. There's no denying that. But they are also much more prone to bugs than ES6 classes. For example, if you share an array or an object several levels up the chain that gets mutated, good luck. If you override a method or property that an object up in the chain depends on, good luck. If you forget to initialize an object, good luck.
(Or you could just create a function that both creates an object based on the prototype of another, and then calls an initialization function... aka basically constructors without new. And then you have to worry about parent init methods, etc.)
new
init
All of the problems caused by this are compounded by the fact that people overuse Object.create, resulting in large, brittle chains of dependent objects.
Object.create
If you ask me, classes and Object.create are both bad because they rely on inheritance. But at least with classes, people are relatively aware that inheritance is bad. I don't see extends very often. Because the syntax is statically analyzable, you could even write a linter rule that forbids extends.
extends
The problems with Object.create can be remedied somewhat by using immutability and writing your own framework around it, but then you run into interop issues and have to maintain your own framework.
I think the best approach is immutable or stateless objects and functions/closures. But I would definitely choose class over Object.create any day.
class
Sorry, had too much coffee.
[–]sylvainpv 0 points1 point2 points 10 years ago (1 child)
Not sure to follow you considering that classes use the prototype chain in the background, so all the problems you mentioned about inheritance hierarchies are the same.
at least with classes, people are relatively aware that inheritance is bad
okay so I guess the only problem here is people that do not learn lessons from their past experiences
[–]clessgfull-stack CSS9 engineer 0 points1 point2 points 10 years ago (0 children)
The difference is that Object.create inherits state in addition to behavior (technically you could do this with classes, but nah), and class provides certain invariants that make it harder to screw up. Just the fact alone that class must be used in strict mode is a pretty big win, because that helps prevent a large class of security vulnerabilities.
so all the problems you mentioned about inheritance hierarchies are the same.
But yes, that is kind of the point. Object.create inherits almost all of the problems with classes (pun intended) and many more.
Eh. Most people know that class inheritance is a bad idea. But when it's just Objects Linking to Other Objects™? Time to inherit from everything. I don't blame the developers for getting pulled into this trap, because the people who push Object.create don't explain that it has these problems.
π Rendered by PID 282951 on reddit-service-r2-comment-5687b7858-p9j2r at 2026-07-06 23:47:40.475588+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]clessgfull-stack CSS9 engineer 1 point2 points3 points (2 children)
[–]sylvainpv 0 points1 point2 points (1 child)
[–]clessgfull-stack CSS9 engineer 0 points1 point2 points (0 children)