Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document namespaces in JavaScript?

How can namespaces be documented in JavaScript with jsDoc?

Here is my attempt, is this right?

/**
 * My special namespace
 *
 * @name my.namespace
 * @namespace
 */
$namespace('my.namespace', /** @lends my.namespace **/ {
    /**
     * Foo - does something really neat...
     * @function
     */
    foo: function() {
    }
});

Just to clarify, the above is used as follows:

my.namespace.foo();
like image 479
Lea Hayes Avatar asked Aug 26 '11 15:08

Lea Hayes


People also ask

How does namespace work in JavaScript?

Namespace refers to the programming paradigm of providing scope to the identifiers (names of types, functions, variables, etc) to prevent collisions between them. For instance, the same variable name might be required in a program in different contexts.

How do you explain a namespace?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.

What is declare namespace?

The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.


1 Answers

This feature is available in jsdoc3 micmath/jsdoc. The syntax of jsdoc3 is different to jsdoc-toolkit (jsdoc2)

The following example was by Michael jsdoc and pseudo-namespaces?

/**
* Document me.
* @namespace my
*/

/**
* My special namespace
* @namespace my.namespace
*/
$namespace('my.namespace', /** @lends my.namespace **/ {
   /**
    * Foo - does something really neat...
    */
   foo: function() {
   }
});
like image 188
Lea Hayes Avatar answered Sep 29 '22 06:09

Lea Hayes