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

157
Views
Can Javascript Class methods still be considered "pure", if they call other "pure" class methods?

Consider

class Service {
    methodA(input: string[]): number {
        const resB = this.methodB(input);
        return resB * 2;
    }
    methodB(input: string[]): number {
        return input.length;
    }
}

If MethodB is a pure function, can MethodA also be considered a pure function?

What about the case, when MethodB is a pure function from an injected class?

class Service {
    constructor(helper:Helper){}
    methodA(input: string[]): number {
        const resB = this.helper.methodB(input);
        return resB * 2;
    }
}

In both cases I argued yes in my team, because both cases no side effects takes place and the input>output is deterministic.

On the other side, let alone the the fact, that MethodA was using this. inside its function body was enough for other to say no.

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!