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

139
Vistas
Square Brackets after function execution

What is the purpose/ how does it work when declaring a function like:

myObj.request({myParam: null })[something](from, (error, res, body){
   //code
})

What is the behavior of this code? I don't get the meaning of [something] and the anonymous function that follows

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

0

i dont know the implementation details of your posted code so i can just guess:

myObj.request() will return an array/object of functions. With [something] you will select one of those functions and invoke it afterwards. As said, thats only guessing whats going on as you didnt provide any context. For example:

const myObj = {
  request: () => ({ 
    a: () => console.log('i am fn a'), 
    b: () => console.log('i am fn b'), 
  })
}

myObj.request()['a']() // console.logs 'i am fn a'

NOTE: for simplicity reasons i did not pass any arguments/callbacks to the functions. If you still have questions let me know and i'll update the answer

about 4 years ago · Juan Pablo Isaza Denunciar

0

Javascript evaluates the expression inside square bracket, in your case the value for something and will executes the function with that name.

For example in your case

myObj.request({myParam: null })[something]

If the value of something is "get" as string. It will simply executes

myObj.request({myParam: null })["get"]

OR

myObj.request({myParam: null }).get

Its just like accessing a prperty inside an object, where myObj.request({myParam: null }) is the object and value for something is the property inside that object.

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