最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Questions about documenting nested array and object data with jsDoc - Stack Overflow

matteradmin8PV0评论

How do I format nested arrays and objects using jsdoc?

This is my best guess:

an_obj = { 
        username1 : [
            {
                param1 : "value 1-1-1",
                param2 : "value 1-1-2",
                optional_nested : "1-1--2"
            },
            {
                param1 : "value 1-2-1",
                param2 : "value 1-2-2"
            },
        ],
        username2 : [
            {
                param1 : "value 2-1-1",
                param2 : "value 2-1-2"
            },
            {
                param1 : "value 2-2-1",
                param2 : "value 2-2-2",
                optional_nested : "2-2--2"              

            }
        ]
    }
}


/**
 * A function description.
 * @param {Object} obj
 * @param {Object} obj.username  This is not the object name, but a name type. 
 * @param {Array}  obj.username.array Desc...  using [] would conflict with optional params.
 *                                    However this could be confused with an object called array.
 * @param {String} obj.username.array.param1 Desc... This is the object name rather than a type.
 * @param {String} obj.username.array.param2 Desc... 
 * @param {String} obj.username.array.[optional_param] Desc... 
 */
var myFunc = function(obj){
    //...
};
myFunc(an_obj);

How do I indicate that an object is indexed by a kind of string?

How do I define a nested array?

Also not sure where to put the square brackets in the optional parameter.

How do I format nested arrays and objects using jsdoc?

This is my best guess:

an_obj = { 
        username1 : [
            {
                param1 : "value 1-1-1",
                param2 : "value 1-1-2",
                optional_nested : "1-1--2"
            },
            {
                param1 : "value 1-2-1",
                param2 : "value 1-2-2"
            },
        ],
        username2 : [
            {
                param1 : "value 2-1-1",
                param2 : "value 2-1-2"
            },
            {
                param1 : "value 2-2-1",
                param2 : "value 2-2-2",
                optional_nested : "2-2--2"              

            }
        ]
    }
}


/**
 * A function description.
 * @param {Object} obj
 * @param {Object} obj.username  This is not the object name, but a name type. 
 * @param {Array}  obj.username.array Desc...  using [] would conflict with optional params.
 *                                    However this could be confused with an object called array.
 * @param {String} obj.username.array.param1 Desc... This is the object name rather than a type.
 * @param {String} obj.username.array.param2 Desc... 
 * @param {String} obj.username.array.[optional_param] Desc... 
 */
var myFunc = function(obj){
    //...
};
myFunc(an_obj);

How do I indicate that an object is indexed by a kind of string?

How do I define a nested array?

Also not sure where to put the square brackets in the optional parameter.

Share Improve this question asked Feb 20, 2012 at 16:53 SystemicPluralSystemicPlural 5,78912 gold badges54 silver badges75 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

You can try doing it like this : (as specified here http://code.google./p/jsdoc-toolkit/wiki/TagParam)

/**
* @param {String[]} obj.username.array
*/

This is supposed to declare obj.username.array as an array of strings. Are you using jsdoc or jsdoc3?

I'd remend checking this out. I'd probably write it something like this:

//{Object{username:<Array<Object{param1:String, param2:String,[optional_nest]:string}>>}}
Post a comment

comment list (0)

  1. No comments so far