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

224
Views
Llamar a funciones de una clase a través de apply no inicializa los valores en el constructor

Tengo clases de javascript en varios archivos. Me gustaría llamar a una función de una clase determinada proporcionando solo sus nombres como argumentos.

 class Index{ constructor(){ this.Loader("test", "TestFunc"); } Loader(cname, fname){ const template = require(`./${cname}.js`); const object = new template(); object[fname].apply(); } } new Index();
 module.exports = class Test{ constructor(){ this.text = "this text should appear"; } TestFunc(){ console.log(this.text); } }

Cuando la instancia de la clase Test se inicializa, el constructor se ejecutará y preparará el valor, pero cuando llamo a TestFunc a través de la función de aplicación, los mismos valores aparecen indefinidos y aparece el error "No se puede leer el texto de propiedad de indefinido". Al llamar a la función normalmente a través de object.TestFunc(); tal error no está presente.

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!