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

307
Views
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 answers
Answer question

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 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!