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

81
Views
Función de llamada desde como una cadena en nodejs

Tengo esta matriz de objeto:

 let choices = [ {title: 'Single Card Payment', func: 'singleCard'}, {title: 'Monthly Card Payment', func: 'monthlyCard' }, {title: 'Monthly Direct Debit Payment', func: 'monthlyDD'} ]

Lo estoy recorriendo y me gustaría llamar a funciones con el valor de la func, como esta (que obviamente es incorrecta)

 for(choice for choices) { choice.func('some', 'params'); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede crear un objeto con métodos. Como abajo

 const funcs = { singleCard: () => { console.log('single card called ')} }

Y luego llamar así

 for (i in choices) { funcs[choices[i].func]() }
about 4 years ago · Juan Pablo Isaza Report

0

usando la funcion malvada :

 let choices = [ {title: 'Single Card Payment', func: 'singleCard'}, {title: 'Monthly Card Payment', func: 'monthlyCard' }, {title: 'Monthly Direct Debit Payment', func: 'monthlyDD'} ] for(i in choices) { eval(choices[i].func)('some', 'params'); }

editar: es eval chicos no malvados. 0K.

about 4 years ago · Juan Pablo Isaza Report
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!