Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
Using JavaScript reflection to invoke a function

I am new to JavaScript and am struggling with how reflection works there. What I want to do is: Given a String which is the function's name, invoke that function. E.g. var myString = "myFunctionName()" is given and then I want to invoke myFunctionName() using myString somehow.

Is this possible and how?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It all depends on the context in which the function is declared.

For the browser's window context:

function test() {
  console.log('Hello world!');
}

const string = 'test';

window[string]();

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try:

function myFunctionName() {
  // do something...
}

var myString = "myFunctionName()";

eval(myString) 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda