views:

211

answers:

1

What is the proper way to document objects of this style in jsdoc:

/**

*/

var strings = 
{
    /**

    */ 
    stripHTML: function(html)
    {
     //does something
    },
    /**

    */
    validHTML: function(html)
    {
     //does something else
    }
}

Namely the proper parameter to define the object, and to recognize the sub-functions as part of 'strings'. I know about @param, @return etc, I just don't know the main definition for this type of object.

+2  A: 

I would use @namespace for "strings"

the methods would simply use @function (though it's obvious to jsdoc what they are

Edit In your particular example you may want to use something like:

/**
    describe purpose
*/
String.prototype.stripHTML = function()
{
    //does something with this
}

/**
    describe purpose
*/
String.prototype.validHTML = function()
{
    //does something else with this
}

then used like this:

var str = "bob<br/>";
str = str.stripHTML();
Jonathan Fingland
Thanks for the answer.I know about the prototypes, but thanks for the tip. The script I used as a demo has somewhat misleading names.
Ian Elliott
ahhh, ok. well, for singletons that function as a namespace, just use the @namespace. It does get to be a pain when you have complex structures, though
Jonathan Fingland
Is there any way of marking the function, say 'validHTML', so that it appears to be a method of or linked to 'strings'? Looking at the generated documentation there's no way to really tell that it's a member of such.
Ian Elliott
the jsdoc documentation generators don't really have an understanding of the built-in objects, just the grammar. you can use @memberOf to explicitly define the relationship though
Jonathan Fingland
are you familiar with the jsdoc-toolkit wiki at http://code.google.com/p/jsdoc-toolkit/w/list
Jonathan Fingland
I am, but am still having problems with it. When I use memberOf it throws the error '>> WARNING: Trying to document saveContent as a member of undocumented symbol saveState\.' I feel like I've tried all possible tags but can't get the two to link up.
Ian Elliott
For the above ^^ :/** @namespace */ var saveState = { /** @memberOf saveState */ saveContent:function() {} }
Ian Elliott
in that case, @memberOf would not be appropriate as saveState isn't an instantiation of a class. you want /** @static */ saveContent:function().... see http://code.google.com/p/jsdoc-toolkit/wiki/TagStatic
Jonathan Fingland
I'm going to have to sincerely apologize for the last few comments... It turns out I was not saving over the original due to a small typo in the file name. The jsdoc was in-fact catching them properly as static. Thanks for your patience!
Ian Elliott
hehe, no worries. Glad it's all sorted out.
Jonathan Fingland