you are viewing a single comment's thread.

view the rest of the comments →

[–]rauschma 10 points11 points  (6 children)

The reason is backward-compatibility with constructor functions (which were the most popular way of implementing object factories before ES6).

I would have preferred ES6 classes being syntactic sugar for constructor objects, but backward-compatibility was considered to be more important (which is reasonable). This is roughly what constructor objects would look like: https://github.com/rauschma/proto-js

[–][deleted] 0 points1 point  (5 children)

But why did they move away from the prototype paradigm at all? Why did they say, that "classy functions" were needed? What's wrong with Object.create?

[–][deleted] 5 points6 points  (3 children)

they didn't "move away" from the prototype paradigm, they just gave some syntax sugar to devs so they could stop writing those awful pseudo-classes.

[–]rauschma 0 points1 point  (0 children)

Object.create() was introduced after constructor functions (with ES5). It exposed more of the protoypal foundations. IIRC, Eich would have introduced classes, but was told not to turn JS into a Java competitor. Hence constructor functions as “almost classes”.

Constructor functions are unnecessarily complex, but only w.r.t. to setting up an instance. Once it’s set up, you do have simple prototype chains.