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

153
Vistas
How to execute a function from the value of a map object

I want to be able to execute a function which is saved as a value on Map object by referencing the key. For example:

const myMap = new Map();

myMap.set("myKey", function(argument) {
    console.log(argument);
});

let value = myMap.get("myKey");
console.log(value);

The function is output to the console but I can't figure out how to actually execute the function.

I tried let test = new Function(value) but got the error message "Function statements require a function name"

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

0

Invoke the function with parentheses:

const myMap = new Map();

myMap.set("myKey", function(argument) {
    console.log(argument);
});

let value = myMap.get("myKey");
value('Hello World!')

about 4 years ago · Juan Pablo Isaza Denunciar

0

As get method of myMap will give you the function, You just have to invoke it as

myMap.get("myKey")("Hello World!")

const myMap = new Map();

myMap.set("myKey", function (argument) {
  console.log(argument);
});

let value = myMap.get("myKey")("Hello World!");

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