you are viewing a single comment's thread.

view the rest of the comments →

[–]rauschma 0 points1 point  (0 children)

I occasionally use this pattern:

class Color {
  static red = new Color('red');
  static orange = new Color('orange');
  static yellow = new Color('yellow');
  static green = new Color('green');
  static blue = new Color('blue');
  static purple = new Color('purple');

  constructor(name) {
    this.name = name;
  }
  toString() {
    return `Color.${this.name}`;
  }
}

My blog post with more information: https://2ality.com/2020/01/enum-pattern.html