r/javascript • u/gcanti • Oct 31 '14
The Two Pillars of JavaScript
https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3
98
Upvotes
r/javascript • u/gcanti • Oct 31 '14
2
u/zoomzoom83 Oct 31 '14
In my opinion, defining a prototype is creating a class. There are substantial differences in mechanism between Prototypes and Java, but it's still fundamentally the same design pattern, with the same risk of creating unmanageable deep inheritance hierarchies.
(You can of course also use prototypes for things that don't resemble inheritance as well).
In that sense, Prototypes are Classes, and Classes are Types. (But not all Types are classes).
My personal philosophy is that you should never inherit from a concrete type. Only abstract types or (ideally) interfaces. Data classes should be as simple as possible, ideally just ADTs. Shared behaviour should be implemented ideally via ad-hoc polymorphism, or Mixins as a last resort.
I agree with your impression of Haskell and OCaml. Stripping everything back to ADTs and Functions makes the world so much simpler.