Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
Options for passing and describing arguments to js function

What other options are there for passing and using arguments in a function using an object besides these two?

Option 1:

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

Option 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 Respostas
Responde à pergunta

0

Those, or other ways of spinning them, are basically it. Well, those and using an array, but if you use an array you may as well use discrete parameters, you'll have the same issue with order being significant and the problems with that as you get to more than three parameters.

Another way to spin what you have:

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

You've said "...and describing" in the title but not the text. If that part is important to you, you can describe these more completely by using JDDoc annotations, which many IDEs can read and present to you (even if you never actually run JSDoc) when you're using the function:

/**
 * 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
}) {
    // ...
};

Similarly, if you create a TypeScript type/interface and document its properties, IDEs will show that to you as well.

/**
 * 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda