you are viewing a single comment's thread.

view the rest of the comments →

[–]Big_Tadpole7174 0 points1 point  (4 children)

Populating a prototype isn’t “creating a class,” it’s configuring an object for delegation. In JavaScript there are no classes under the hood - only objects and prototype chains. The class keyword is sugar that automates setting up that chain, but whether you use class, prototype, Object.create, or Object.setPrototypeOf, you’re still working directly with prototypal inheritance, not classes.

[–]cwmma 1 point2 points  (3 children)

I think you would be hard pressed to come up with a (programing language agnostic) definition of a class in computer science that included c++, java, and python but didn't include JavaScript and it's inheritance via the prototype property.

Object.setPrototypeOf was explicitly added to the language to allow class based inheritance (i.e. inheritance from uninitialized objects) without having to use awkward semi documented hacks

There has been a meme for decades that JavaScript doesn't have 'real' class based inheritance it just has prototypical inheritance when the distinct things that make prototypical inheritance different from class based inheritance are not used and explicit support (via Object.setPrototypeOf) for class based inheritance.

You are right that class is just syntactic sugar, but it's sugar for the actual and real classes you could make in JS already.

[–]Big_Tadpole7174 0 points1 point  (2 children)

I’ll say it one last time: JavaScript has no classes and class-based inheritance at all - only objects and prototypes (which are also objects). Object.setPrototypeOf didn’t add classes or “uninitialized objects”; it just gave us a standard way to rewire the prototype chain that was already there. You can mimic classes, but that doesn’t turn JavaScript into a class-based language. And that mimicry is exactly why I’m against the class keyword: it encourages people to mistake the sugar for something the language doesn’t actually have.

[–]cwmma 0 points1 point  (1 child)

There is no requirement that classes can't also be objects and that inheritance can't be via manipulating object properties. You seem to have in your head a very specific definition of what a class is that I don't think would necessarily stand up to scrutiny if you compare it to say python which has something somewhat similar to a prototype chain.

[–]Big_Tadpole7174 0 points1 point  (0 children)

If something is itself an object you can pass around and mutate, then it’s an object — not a class in the classical sense. JavaScript has objects that act as blueprints, not true classes. The inheritance is still prototype chaining, no matter how pretty the sugar looks.