JavaScript Prototypal Inheritance

The cluster discusses JavaScript's prototype-based inheritance model, emphasizing that ES6 classes are syntactic sugar over prototypes, and debates whether developers should embrace prototypal patterns or push for class-based OOP like in Java or C#.

📉 Falling 0.2x Programming Languages
2,557
Comments
20
Years Active
5
Top Authors
#5148
Topic ID

Activity Over Time

2007
3
2008
23
2009
51
2010
106
2011
176
2012
254
2013
182
2014
163
2015
280
2016
142
2017
258
2018
183
2019
120
2020
121
2021
139
2022
112
2023
126
2024
71
2025
46
2026
1

Keywords

OO OP JS ML IS OOP JavaScript ES6 wikipedia.o LOC inheritance javascript class classes js prototypes syntactic sugar syntactic oop prototype

Sample Comments

soapdog Jan 12, 2019 View on HN

people keep wanting to make JS fit into the space of C#/Java OOP class-based stuff. Prototypical inheritance is so cool and useful and lightweight, this is quite versatile once you understand the mechanisms and how to bind it. Why people keep trying to "fix" JS so that it conforms to their class-based expectations is beyond me. I like how it works now.

irrational Jul 19, 2022 View on HN

The newer class based IS the original prototype based. Class is literally just syntactic sugar on top of prototype inheritance. It was just added to help people coming from true OOP languages to feel comfortable. Notice, for instance, in Java the class acts as a blueprint for the object. You can’t have the object without the class. Not so in JS. The class is just window dressing and is not required at all.

Vinnl Mar 12, 2020 View on HN

Aren't classes in Javascript mostly syntactic sugar to make inheritance easier?

s__s May 5, 2022 View on HN

JavaScript classes are nothing more than syntactic sugar. It’s still prototype-based inheritance under the hood.Prototypal Inheritance is considered one of JavaScript’s strong points, and many, including myself don’t think the class syntactic sugar that was added has much value. If anything it just confuses new developers.A lot of JavaScripts detractors simply don’t understand the language very well.

jorblumesea Aug 3, 2017 View on HN

True "Classes" in JS always seemed like a hack anyways. It will never be true OOP, so why shoehorn these concepts into it? Especially given prototypical inheritance patterns we will never have real java style oop patterns. Except for primitives, almost everything is an object, but they are basically hashmaps, not real classes or objects as someone from other languages might think of them.Imo, the language was not build or designed for some of these heavier OOP concepts. Just my opin

andrewmcwatters May 30, 2023 View on HN

Try writing some code in not just JavaScript but also C, C++, Java, and others. Classes aren't some relic. You use prototypes in JavaScript every single day.

SzamarCsacsi Mar 26, 2020 View on HN

Classes in JavaScript are just syntactic sugar around prototypes.

stupidcar Aug 3, 2017 View on HN

You realise JS classes are syntactic sugar for prototypes, right?

sh1mmer Apr 27, 2010 View on HN

Rather than doing this why not just read "JavaScript: The good part" and learn about JavaScript's classes instead.

ccanassa Jan 15, 2012 View on HN

JavaScript is object oriented but it gets the inheritance from prototypes instead of classes. Prototypes are very powerful, you can implement a class system in JavaScript if you want to but the reverse is not true.