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#.
Activity Over Time
Top Contributors
Keywords
Sample Comments
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.
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.
Aren't classes in Javascript mostly syntactic sugar to make inheritance easier?
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.
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
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.
Classes in JavaScript are just syntactic sugar around prototypes.
You realise JS classes are syntactic sugar for prototypes, right?
Rather than doing this why not just read "JavaScript: The good part" and learn about JavaScript's classes instead.
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.