Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda