Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:52:50+00:00 2026-06-03T07:52:50+00:00

Related: Correct way to document open-ended argument functions in JSDoc I’ve a function that

  • 0

Related: Correct way to document open-ended argument functions in JSDoc

I’ve a function that accepts multiple arrays by accessing the arguments variable:

/**
 * @param options An object containing options
 * @param [options.bind] blablabla (optional)
 */
function modify_function (options) {
    for (var i=1; i<arguments.length; i++) {
        // ...
    }
}

Now, I know that each argument besides options is an array containing values that are worth documenting:

[search_term, replacement, options]

I’m not considering putting the (lengthy) description in the variable parameter line.

@param {…} An array with search terms, replacements and its options; index 0: the search term within the function; 1: the replacement text; 2: optional options (catch_errors: catches errors and log it, escape: escape dollars in the replacement text, pos: “L” for placing the replacement before the search term, “R” for placing it after)
Not a readable solution and the type is not visible.

Is there a way to document the types and values of a variable parameter?

@param {...[]} An array with search terms, replacements and its options
@param {...[0]} The search term within the function
@param {...[1]} The replacement text 
@param {...[2]} An optional object with obtions for the replacement
@param {...[2].catch_errors} catches errors and log it
@param {...[2].escape} etc...

The above looks ugly, but it should give you an idea of what I’m trying to achieve:

  • document the type of a variable parameter (in this case an Array)
  • document the values of this array
  • document the properties of an object inside this array

For laziness, I’ve used an array instead of a object. Other suggestions are always welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:52:51+00:00Added an answer on June 3, 2026 at 7:52 am

    Your function is not truly variable arguments, you should just change its signature to what foundrama suggested. Except that JSDoc has syntax a little better than foundrama suggested

    /**
     * @param {String} searchTerm
     * @param {String} replacementText
     * @param {Object} opts (optional) An object containing the replacement options
     * @param {Function} opts.catch_errors Description text
     * @param {Event} opts.catch_errors.e The name of the first parameter 
     *         passed to catch_errors
     * @param {Type} opts.escape Description of options
     */
    

    And you’d call it like

    modify_text('search', 'replacement', {
        catch_errors: function(e) {
    
        },
        escape: 'someEscape'
    
    });
    

    If you really do have a case for varargs style, it should be a variable of the same type that can be passed at the end of the parameter list, I document it like the following, though it’s not a JSDoc standard, it’s what Google uses with their documentation

    /**
     * Sums its parameters
     * @param {...number} var_args Numbers to be added together
     * @return number
     */
    function sum(/* num, num, ... */) { 
        var sum = 0;
        for (var i =0; i < arguments.length; i++) {
          sum += arguments[i];
        }
        return sum;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the correct way of making checkboxes that are related to a certain question
I look into every answers on stack overflow related to that argument but i
Related to an earlier question I asked, I've seen that there's both LoadComponent() and
Related to my question here but not enough to open a new question. I
I am creating a control that loads three related dropdownlists at runtime, and all
This is a question related to C# MVC2 Jqgrid - what is the correct
What is the correct way to structure headers? There are some similar-ish questions but
Similar to this question: Checkboxes on Rails What's the correct way of making radio
I'm struggling to figure out the correct way to do something in MVC which
Related question: Moving repository trunk to another’s branch (with history) I know that one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.