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

237
Views
Is it possible to call an already declared method dynamically from within a class in javascript?

So I have a class with some private methods with the same prefix. And I wanted to do a public method that can call them using the prefix and a suffix with an idea like this :

class MyClass {
   #privateMethod1(){
      console.log("Hello");
   }
   #privateMethod2(){
      console.log("world");
   }
   #privateMethod3(){
      console.log("!");
   }
   publicMethod(...names){
      names.forEach((name) => {
         this.["#privateMethod"+`${name}`]();
      });
   }
}
let test = new MyClass();
test.publicMethod(1,2,3); // Should display "Hello world!"

But is it even possible? I tried to use objects but nothing seems to work

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!