Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the correct way to document a jQuery parameter type with JSDoc?

Tags:

I'm trying to document my program with the JSDoc syntax for myself and the people that will have to look at my code. I'm also trying to improve my skills.

For a parameter of the jQuery type, I'm a little puzzled. I know that's an object, but it's fairly common in my program, so I think I should first declare a typedef for the jQuery type, then use it as my parameter type. So I ask, would it be the correct way to do it?

/**  * DOM object referenced by jQuery  * @typedef {jQuery} $jQueryDomObject  */  /** * SOAP call that does ... * * @param {string} code Some desc ... * @param {callback} fnctVa Some desc ... * @param {$jQueryDomObject} $attrib Input field that ... */ myfunction = function (code, fnctVa, $attrib) {}; 

I also found on SO this question, somewhat similar:
How can I get JSDoc to mark my param as a jQuery object?

like image 519
Jean-Philippe Martin Avatar asked Nov 27 '13 20:11

Jean-Philippe Martin


People also ask

What is the Jsdoc keyword to specify an argument to a function?

The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting.

What is $$ in jQuery?

$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.


1 Answers

For a parameter that is a jQuery object, I often just do:

@param {jQuery} foo 

And do not further define what jQuery is. It is known well enough. However, if you want, you can do this with jsdoc 3:

/**  * jQuery object  * @external jQuery  * @see {@link http://api.jquery.com/jQuery/}  */  /**  * SOAP call that does ...  *  * @param {string} code Some desc ...  * @param {callback} fnctVa Some desc ...  * @param {external:jQuery} $attrib Input field that ...  */ var myfunction = function (code, fnctVa, $attrib) {}; 
like image 101
Louis Avatar answered Sep 21 '22 18:09

Louis