Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!