5
votes

I'm editing a js file with JsDoc to get a clean documentation. My structure is quite simple:

/**
 * Finds an object
 * @param {string} prop - Property
*/

Array.prototype.findObject = function _findObj(prop, val){
    // blablabla
}


function myfunc(plep){
    // does something
}

/**
 * Workshop Namespace
 * @namespace
*/

var Workshop = {};


/**
 * Does something great
 * @param {*} plep - My super param!
*/
Workshop.doIt = myfunc;

/**
 * It works!
 * @param {string} fly - my flying param
*/
Workshop.flyNow = function _flyN (fly){
    // fly!
}

However,

  1. Documentation for first function is not displayed.
  2. Workshop namespace IS created
  3. Workshop.doIt is documented only by its description, arguments are not
  4. Workshop.flyNow is well documented

Does anyone know why?

Thanks!

3

3 Answers

4
votes

Here's why:

1.

First function is not documented because it does not belong to any recognisable namespace. To fix this issue, you could create a virtual namespace as follows:

/** * @namespace Array */

And you can improve the documentation of the function as follows:

/**
 * Finds an object.
 *
 * @param {string} prop Property name.
 * @param {string|number|function|object} val Value.
 *
 * @function findObject
 * @memberof Array#
 */
Array.prototype.findObject = function _findObj ( prop, val ) {
    // blablabla
}

With the outcome below enter image description here

3.

Arguments weren't documented because the JSDoc parser does not recognise Workshop.doIt( ... ) as a function. That can be fixed with the @function or @method tag:

/** * Does something great * @param {*} plep - My super param! * * @method */ Workshop.doIt = myfunc;

And the result look like this:enter image description here

1
votes

Does Array exist as symbol? If not then that is the reason this is not getting documented.

Regarding the parameter, are you sure * is a valid type? Can you try Object?

1
votes
/**
 * Finds an object
 * @param {string} prop - Property
*/

Array.prototype.findObject = function _findObj(prop, val){
    // blablabla
}

/**
 * Does something great
 * @param {*} plep - My super param!
 */
function myfunc(plep){
    // does something
}

/**
 * Does something great
 * @param {*} plep - My super param!
 * @function
 */
var alternativeDoIt = function myfunc2(plep){
 // does the same thing
}

/**
 * Workshop Namespace
 * @namespace
*/

var Workshop = {};


/**
* Does something great 2
* @function (<== check if this is useful)
*/
Workshop.doIt = myfunc;

Workshop.doIt2 = alternativeDoIt;

/**
 * It works!
 * @param {string} fly - my flying param
*/
Workshop.flyNow = function _flyN (fly){
    // fly!
}