Hacker News new | past | comments | ask | show | jobs | submit login

Honestly I don’t think it does a good job at explaining it. Classes are mostly syntax sugar for “old” constructors and prototypes, not the other way around (that’s the whole reason you can’t tell them apart). Would be easier to explain it that way; on mobile right now so can’t comment too much.



I thought it was unfortunate that prototypes were characterized as an inadequate approximation of classes, when in fact prototypes are a wholly legitimate, powerful, and certainly interesting way to approach object-oriented programming (https://en.m.wikipedia.org/wiki/Prototype-based_programming).

20+ years of confused programmers suggests that maybe it wasn't the right way to go for a language that is frequently used by beginners, but still that wasn't the fault of prototype based programming itself.

The new class system is syntactic sugar leveraging the power of prototypes. This was always possible, and nothing stopped you from implementing a class-like system in JavaScript a long time ago.

More, very readable, info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...


I tried not to mention classes too explicitly in the section that deals with __proto__, and only explain the prototypes themselves. But keep in mind that new readers are often exposed to classes only so they need some practical ground. In any case there's plenty of resources -- maybe my explanation will click with somebody.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: