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

309
Vistas
Opciones para pasar y describir argumentos a la función js

¿Qué otras opciones hay para pasar y usar argumentos en una función usando un objeto además de estos dos?

Opción 1:

 let timerClosure = function ({ period, // number funStart, // function funEnd, // function funStartArguments = [], funEndArguments = [], warming = 0 }) {// something }

Opcion 2:

 let timerClosure = function (timerConfigObj) { let period = timerConfigObj.period; // number let funStart = timerConfigObj.funStart; let funEnd = timerConfigObj.funEnd; let funStartArguments = timerConfigObj.funStartArguments || []; let funEndArguments = timerConfigObj.funStartArguments || []; let warming = timerConfigObj.warming || 0; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Esas, u otras formas de hacerlos girar, son básicamente eso. Bueno, eso y usar una matriz, pero si usa una matriz, también puede usar parámetros discretos, tendrá el mismo problema con el orden significativo y los problemas con eso a medida que llega a más de tres parámetros.

Otra forma de girar lo que tienes:

 let timerClosure = function (timerConfigObj) { const { period, // number funStart, // function funEnd, // function funStartArguments = [], funEndArguments = [], warming = 0 } = timerConfigObj; // ... };

Has dicho "... y describiendo" en el título pero no en el texto. Si esa parte es importante para usted, puede describirla de manera más completa mediante el uso de anotaciones JDDoc , que muchos IDE pueden leer y presentarle (incluso si nunca ejecuta JSDoc) cuando usa la función:

 /** * Does something nifty with timers and closures. * * @param {Object} options - Options for the nifty thing. * @param {number} options.period - `period` description... * @param {function} options.funStart - `funStart` description... * @param {function} options.funEnd - `funEnd` description... * @param {array} options.funStartArguments - `funStartArguments` description... * @param {array} options.funEndArguments - `funEndArguments` description... * @param {number} options.warning - `warning` description... */ let timerClosure = function ({ period, // number funStart, // function funEnd, // function funStartArguments = [], funEndArguments = [], warming = 0 }) { // ... };

Del mismo modo, si crea un tipo/interfaz de TypeScript y documenta sus propiedades, los IDE también se lo mostrarán.

 /** * Options for `timerClosure` */ interface TimerClosureOptions { /** * Period description... */ period: number; funStart: function; funEnd: function; funStartArguments?: any[]; funEndArguments?: any[]; warming?: number; } /** * Does something nifty with timers and closures. * * @param {TimerClosureOptions} options - Options for the nifty thing. */ let timerClosure = function ({ period, funStart, funEnd, funStartArguments = [], funEndArguments = [], warming = 0 }: TimerClosureOptions) { // ... };
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