Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
Is there a functional reason to prefer a Javascript class with only static methods or a file with functions?

Let's say I've created a class with only static methods like below.

export class JWT {
  static getPayload(token: string): { [key: string]: any } {
    ...
  }

  static isExpired(token: string): boolean {
   ...
  }
}

I've seen libraries with classes like the above. But given all the class methods are static, there's no shared state amongst the functions. Why not instead create a file named jwt.ts with the same functions but no class?

export function getPayload(token: string): { [key: string]: any } {
    ...
  }

export function isExpired(token: string): boolean {
   ...
  }

I could call

import { JWT } from 'file1';
import { getPayload } from 'file2';
Option 1: JWT.getPayload()
Option 2: getPayload()

Is there a functional difference or is this primarily a stylistic difference?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda