Why does the MDN documentation of OOJS advocate classical inheritance?

A common misconception is that that page from MDN is based around classical inheritance, when it's actually not. Sure, it does use some terminology about classes, but that's mostly to explain things, because most people will probably be familiar with those concepts.

And you might say, but it is using new and it is using constructor functions. Yes, it is. And it is building a prototype chain. Using new and constructor functions is a different thing from "doing inheritance the classical way". For inheritance, the MDN page is building the prototype chain manually (Student.prototype = Object.create(Person.prototype);) and it is using delegation (Person.call(this, firstName);).

While I don't much share Eric Elliot's opinion (but I do respect it), what he proposes is not that far from what the MDN shows. The difference is the usage of constructor functions which Eric Elliot discards. Now, could we then think that the difference "class based" vs "prototype based" lies in the use of constructor functions? Not really. As I said, Mr. Elliot's way is not that far from the MDN article. What is far, what could be considered the opposite, what Mr.Elliot argues against is actually mimicking classical inheritance: by having some sort of entity representing a "class", as understood in class based languages. This is what some libraries/frameworks actually do. Using first a definition of a "class", which is different form a constructor function, and then "instantiation of instances" based on that "class". This is what you should probably avoid. This is what some libraries/frameworks promoted/still promote.

So, what is the real difference between what Mr. Elliot says and what the MDN article presents? Basically, the difference is __proto__. Let me explain. The MDN article is showing prototype chain construction mostly as it was originally intended. The key in original way to build a prototype chain was that only functions exposed [[Prototype]]. This is key, because it meant that the only way to build a prototype chain from userland, was using constructor functions. Then someone decided that exposing the [[Prototype]] through __proto__ for all objects was a good idea (IMHO, it wasn't that good, but there's no need to discuss that). From there, all the derived Object.create, Object.assign, Object.getPrototype, etc.

IMHO, Mr. Elliot's article is just too full of "categorical noes". Should we..? No. Can I...? No. But maybe...? No. It's too much of an extreme view. It doesn't mean his approach is wrong, but I prefer avoiding One True Way thinking.

/r/javascript Thread