Questions tagged [jsdoc]

JSDoc is a markup language for adding inline API documentation to JavaScript source code. This is distinct from the various tools that parse and manipulate code that follows the JSDoc syntax.

The JSDoc markup language is similar to the Javadoc syntax, used for documenting Java code, but is specialized to work with JavaScript's more dynamic syntax and therefore unique, as it is not completely compatible with Javadoc. However, like Javadoc, JSDoc allows the programmer to create doclets and tags which can then be translated into published output, like HTML or RTF.

Example:

/**
    Represents a book.
    @constructor
    @param {string} title - The title of the book.
    @param {string} author - The author of the book.
 */
function Book(title, author) {
}

The following annotations are commonly used in modern JSDoc, but the full list varies between implementations:

  • @param Documents a method parameter; a datatype indicator can be added between curly braces
  • @return Documents a return value
  • @constructor Marks a function as a constructor
  • @deprecated Marks a method as deprecated
  • @private Signifies that a method is private
  • @requires Describe a required resource.
  • @this Specifies the type of the object to which the keyword "this" refers within a function.
  • @throws Documents an exception thrown by a method
  • @exception Synonym for @throws
  • @author Developer's name
  • @version Provides the version number of a library
1697 questions
16
votes
6 answers

jsdoc : reference typedef-ed type from other module

Assuming I have a typedef type in a js module // somewhere/foo.js /** * @module */ /** * @typedef Foo * @type {object} * property {string} bar - some property */ Is it possible to reference this type in another module, so that in the HTML…
phtrivier
  • 13,047
  • 6
  • 48
  • 79
16
votes
3 answers

JSDoc support in IntelliJ IDEA

Is there documentation for what JSDoc subset, superset, or mix of the two IntelliJ supports? My motivation for using JSDoc is two-fold: For developers: so IntelliJ can provide better code-completion, code checking, error checking, etc. For runtime…
avernet
  • 30,895
  • 44
  • 126
  • 163
16
votes
2 answers

Using JsDoc3 for large apps, How to group modules into sections/categories/submodules

I am working on an app which will become quite huge in time. I have decided to use JsDoc3 and DocStrap to document all modules. Modules are defined via require.js and in some places they are nested up to 3 or 4 levels deep. Until now I understand…
Adrian Moisa
  • 3,923
  • 7
  • 41
  • 66
16
votes
1 answer

Generate JavaScript documentation directly from source code

I'm looking for a tool to generate the documentation for JavaScript functions and properties even if there are no appropriately formatted comment blocks associated with those functions or properties (like Doxygen does). This comparison between JSDoc…
Greg
  • 8,230
  • 5
  • 38
  • 53
16
votes
3 answers

Angularjs How to generate HTML code Documentation

Does anyone have any experience in documenting/structuring angularjs projects so the JSDoc can generate nice comments (for your directives, controllers, filters etc.) in an HTML format? At the moment it generates one file with the _global class that…
alchemication
  • 5,084
  • 6
  • 22
  • 21
16
votes
2 answers

Is there a JSDoc standard?

I know there are various flavours of JSDoc around. And it seems that each implementation of a JSDoc parser recognizes its own set of tags. For example, consider the differences in tags between http://usejsdoc.org/ and…
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
15
votes
1 answer

JSDoc: How to document an object with mix of dynamic and fixed properties?

Suppose I have a function like so: function validator(obj){ const ret = {}; for (const key in obj){ // Returns a boolean result = validate(key, obj[key]); if (result !== true) ret.error = true; ret[key] = result; } …
yqlim
  • 6,898
  • 3
  • 19
  • 43
15
votes
2 answers

How to run jsdoc on whole directory in ubuntu

I just need to run jsdoc on ai whole directory containing .js files, I am doing this on individual files in ubuntu terminal by issuing command jsdoc abc.js but what I need is to apply this command on all files in the directory at once,so that all…
SQA
  • 151
  • 1
  • 1
  • 4
15
votes
3 answers

Javascript + JsDoc: How to document new ES6 datatypes like map?

I'm trying to use JSDoc in my ES6 project, I'm returning a Map: /** * Some documentation.. * * @returns {undefined} <- This should be replaced */ function returningMap() { const someMap = new Map(); someMap.set("key", {a, b, c}); …
Shikloshi
  • 3,761
  • 7
  • 32
  • 58
15
votes
3 answers

How to document resolved values of JavaScript promises

Given this code : function asyncFoo() { return new Promise(function (fulfill, reject) { doAsyncStuff(function(err, data) { if(err) reject(new Error(err)); else fulfill(new Bar(data)); }); }); } How can I document that…
DarkChipolata
  • 925
  • 1
  • 10
  • 29
15
votes
2 answers

JSDoc inheriting parameter documentation

Let's say I have two functions, where one extends the other. /** * @abstract * @param {Object} settings * @param {Number} settings.x * @param {Number} settings.y * */ function Base(settings) { this.x = settings.x; this.y =…
LongInt
  • 1,739
  • 2
  • 16
  • 29
15
votes
4 answers

How do you document an array of objects as a parameter in JSDoc?

I have an array that looks like this: [{ "name": "c917379", "email": "jim@bmw.de" }, { "name": "c917389", "email": "jane@bmw.de" }] It is an array of arbitrary length with a number of repeating fields (I've reduced this to two…
Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
15
votes
2 answers

How to escape @ sign inside JSDoc comments in NetBeans

I have a simple method in API, that allows searching objects with JSONPath. As its syntax is pretty much unfamiliar to junior developers, i decided to provide some examples within JSDoc comment. Yet, here is the catch, - @ sign is treated as a start…
c69
  • 19,951
  • 7
  • 52
  • 82
14
votes
1 answer

How to specify Date object in jsdoc function parameter?

/** * * @param {?} date */ function diffDays (date){ var utcThis = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds()); var utcOther =…
suchcodemuchwow
  • 848
  • 2
  • 9
  • 27
14
votes
2 answers

Generating TypeScript declarations for re-exported JS functions in a Node.js module

I am trying to emit declarations for types and functions annotated with JSDoc. Those are useful for TypeScript users and generating them from JSDoc means less overhead on our SDK developers. TypeScript users should get one module called Apify and…