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

167
Vistas
How to define options for JavaScript object?

I have function that requires JS Object as one of the parameter. And what I wanted to do is define options that can be passed inside that object. Let me explain what I meant with an example All of us are familiar with fetch() in js. In vscode, whenever we tried to pass the object, it auto-completes with options that can be passed like for code below

fetch(url, {

})

when I type say m inside {}, it suggests all available options start with the letter m (method) and when pressed enter we get something like method: "GET"

I wanted to achieve a similar feature with my function.

I didn't know what am I suppose to look for to get my solution so I have only done a little research with the closest possible query for me on google but I didn't get any solution for this particular problem.

Just a hint or direction will be fine

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

0

This is your editor's intellisense hard at work. If you want to achieve the same thing, just immediately destructure the object you're expecting as a parameter.

Try calling this function, giving it an object as an argument and type the letter n. Your fancy shmancy editor will suggest number1 and number2

const myFunction = ({ number1, number2 }) => {
    return number1 + number2;
};

You can also do this without the immediate destructuring by using TypeScript (and ensuring your editor supports TypeScript - if you're using VSCode then it does):

interface Options {
    number1: number;
    number2: number;
}

const myFunction = (options: Options) => {
    return options.number1 + options.number2;
};
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