Eric Elliott
Jan 8 · 1 min read

If you’re going to use a constructor function, it’s idiomatic to use the class syntax since ES2015. I would only use a class if there’s was a compelling reason. I prefer the factory version for several reasons I have detailed in other blog posts.

TL;DR:

  • Class might invite users to use `extends` (which leads to problems like tight coupling and the gorilla/banana problem).
  • Class defaults to hooking up the prototype chain, enabling `instanceof`, but `instanceof` lies because JS is dynamic, and because `instanceof` always fails across memory realms.
  • Classes force callers to use `new` (they throw if you omit it), which is problematic if you ever want to refactor to use factories (a common refactor).

Eric Elliott

Written by

Make some magic. #JavaScript

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade