Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!