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

134
Visualizações
Is it possible to shorten the code even further?

I am a lover of beautiful and short code, and here a problem arises ... short of course, but not beautiful. Can this code be made more beautiful?

app.post('/xsolla/', (req, res) => new Xsolla(req, res));

tried this option but it didn't work😅

app.post('/xsolla/', new Xsolla);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

One option is to use rest parameters instead of repeating them:

app.post('/xsolla/', (...args) => new Xsolla(...args));

But keep in mind that readable code is more important than short code.

Reflect.construct (in combination with .bind) would almost do the trick for removing the need to list arguments altogether, but unfortunately it takes the arguments to be passed to the constructor as an array in the second argument, rather than as separate items in the argument list.

about 4 years ago · Juan Pablo Isaza Relatório

0

If you were doing this in multiple places and just wanted to avoid repeated code, you could make yourself a reusable request handler:

function xHandler(req, res) {
    new Xsolla(req, res);
}

app.post('/xsolla/', xHandler);
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