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

170
Vistas
How to change a function based on unknown number of arguments in javascript

Is there any way to add to or manipulate expressions in a returned function?

This is an example for a single argument:

function trackByProp(prop) {
  return function (value) {
    return value[prop];
  };
}

The aim is to extend this function to allow multiple props to be added e.g.

function trackByProp(...props) {
  props.forEach((prop) => {
    //Somehow add value[prop] to the return function???
  });

  return function (value) {
    return; // value[arg1] + value[arg2] + value[argN]
  };
}

Alternatively is there a simpler way to create this function ?

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

0

function trackByProps(...props) {
  return function (value) {
    return props.reduce((result, prop) => result + value[prop], "")
  }
}

Using the properties in the inner function ensures they are available in a closure. similar to the single argument example. Then they can be iterated over each time the inner function is called.

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