The Two Pillars of JavaScript


  • Objects without classes (and prototypal inheritance aka OLOO — Objects Linking to Other Objects), and
  • Lambdas (with closure — the keys to functional programming)

Constructors violate the open/closed principle because they couple all callers to the details of how your object gets instantiated. Making an HTML5 game? Want to change from new object instances to use object pools so you can recycle objects and stop the garbage collector from trashing your frame rate? Too bad. You’ll either break all the callers, or you’ll end up with a hobbled factory function.


You never need classes in JavaScript, and I have never seen a situation where class is a better approach than the alternatives.