Classes Are Useful

It is very common to have the following structure:

  1. function foo() {
  2. let someProperty;
  3. // Some other initialization code
  4. function someMethod() {
  5. // Do some stuff with `someProperty`
  6. // And potentially other things
  7. }
  8. // Maybe some other methods
  9. return {
  10. someMethod,
  11. // Maybe some other methods
  12. };
  13. }

This is known as the revealing module pattern and quite common in JavaScript (taking advantage of JavaScript closure).

If you use file modules (which you really should as global scope is bad) then your file is effectively the same. However there are too many cases where people will write code like the following:

  1. let someProperty;
  2. function foo() {
  3. // Some initialization code
  4. }
  5. foo(); // some initialization code
  6. someProperty = 123; // some more initialization
  7. // Some utility function not exported
  8. // later
  9. export function someMethod() {
  10. }

Even though I am not a big fan of inheritance I do find that letting people use classes helps them organize their code better. The same developer would intuitively write the following:

  1. class Foo {
  2. public someProperty;
  3. constructor() {
  4. // some initialization
  5. }
  6. public someMethod() {
  7. // some code
  8. }
  9. private someUtility() {
  10. // some code
  11. }
  12. }
  13. export = new Foo();

And its not just developers, creating dev tools that provide great visualizations over classes are much more common, and there is one less pattern your team needs to understand and maintain.

PS: There is nothing wrong in my opinion with shallow class hierarchies if they provide significant reuse and reduction in boiler plate.