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

171
Views
Funciones de mapa de búsqueda que se llaman durante la declaración

Estoy tratando de implementar una declaración de cambio alternativa usando un objeto de mapa y las funciones que se supone que deben llamarse de acuerdo con la condición se están llamando mientras declaro el mapa.

Aquí hay un código simplificado de lo que implementé.

 someMethodName(someParams, otherParams) { const verifyThis = callExternalApi(someParams); const customSwitch = { oneValue: this.doThis(otherParams), anotherValue: this.doThat(otherParams), }; const possibleValues = ["oneValue", "anotherValue"]; if (possibleValues.includes(verifyThis)) return customSwitch[verifyThis]; return this.defaultCase(otherParams); }

Puse un archivo console.log en los métodos que se llamarán y descubrí que se están llamando a todos, supuestamente mientras declaro customSwitch, y luego se llama a uno de los métodos al pasar por la cláusula if.

¿Cómo soluciono esto para evitar llamar a mis métodos?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Utilice un objeto cuyos valores sean funciones que, cuando se llamen, invoquen a las otras funciones:

 const customSwitch = { oneValue: () => this.doThis(otherParams), anotherValue: () => this.doThat(otherParams), };

e invocar al volver haciendo

 return customSwitch[verifyThis]();
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!