Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsDoc Namespace

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!

like image 645
Jo Colina Avatar asked Dec 21 '15 10:12

Jo Colina


People also ask

What is a namespace JSDoc?

The @namespace tag indicates that an object creates a namespace for its members. You can also write a virtual JSDoc comment that defines a namespace used by your code. If a namespace is defined by a symbol other than an object literal, you can include a type expression along with the @namespace tag.

What are JSDoc annotations?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.


1 Answers

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

like image 112
Igwe Kalu Avatar answered Oct 22 '22 23:10

Igwe Kalu