Skip to content

Files

Latest commit

 

History

History
35 lines (27 loc) · 535 Bytes

no-static-only-class.md

File metadata and controls

35 lines (27 loc) · 535 Bytes

Pattern: Class with only static members

Issue: -

Description

A class that only contains static members can be replaced with a simpler object literal. Exception: classes with private static fields still need to be classes.

Examples

Example of incorrect code:

class A {
  static a() {}
  static b = 1;
}

Example of correct code:

class A {
  static a() {}
  constructor() {}
}

const obj = {
  a() {},
  b: 1
};

class X {
  static #foo = false; // private field
  static bar() {}
}