2016-09-26 09:56:33 +00:00
|
|
|
---
|
|
|
|
title: Jsdoc
|
|
|
|
category: JavaScript
|
2020-07-04 13:33:09 +00:00
|
|
|
updated: 2020-06-23
|
2017-10-29 12:04:52 +00:00
|
|
|
weight: -1
|
2016-09-26 09:56:33 +00:00
|
|
|
---
|
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
### Functions
|
2016-09-26 09:56:33 +00:00
|
|
|
|
|
|
|
```js
|
2017-10-29 15:49:18 +00:00
|
|
|
/**
|
|
|
|
* This is a function.
|
|
|
|
*
|
2016-09-26 09:56:33 +00:00
|
|
|
* @param {string} n - A string param
|
2021-09-27 01:37:40 +00:00
|
|
|
* @param {string} [o] - A optional string param
|
|
|
|
* @param {string} [d=DefaultValue] - A optional string param
|
2016-09-26 09:56:33 +00:00
|
|
|
* @return {string} A good string
|
|
|
|
*
|
2017-10-29 15:49:18 +00:00
|
|
|
* @example
|
2016-09-26 09:56:33 +00:00
|
|
|
*
|
2017-10-29 15:49:18 +00:00
|
|
|
* foo('hello')
|
2016-09-26 09:56:33 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-27 01:37:40 +00:00
|
|
|
function foo(n, o, d) {
|
2020-06-22 14:38:08 +00:00
|
|
|
return n
|
|
|
|
}
|
2016-09-26 09:56:33 +00:00
|
|
|
```
|
|
|
|
|
2020-08-03 12:27:34 +00:00
|
|
|
See: <https://jsdoc.app/index.html>
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
### Types
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
| Type | Description |
|
|
|
|
| ------------------------------- | ------------------------------------- |
|
|
|
|
| `@param {string=} n` | Optional |
|
|
|
|
| `@param {string} [n]` | Optional |
|
|
|
|
| `@param {(string|number)} n` | Multiple types |
|
|
|
|
| `@param {*} n` | Any type |
|
|
|
|
| `@param {...string} n` | Repeatable arguments |
|
|
|
|
| `@param {string} [n="hi"]` | Optional with default |
|
|
|
|
| `@param {string[]} n` | Array of strings |
|
2019-08-06 10:53:26 +00:00
|
|
|
| `@return {Promise<string[]>} n` | Promise fulfilled by array of strings |
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2020-08-03 12:27:34 +00:00
|
|
|
See: <https://jsdoc.app/tags-type.html>
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
### Variables
|
2016-09-26 09:56:33 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
var FOO = 1
|
2017-10-29 12:04:52 +00:00
|
|
|
```
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
```js
|
2016-09-26 09:56:33 +00:00
|
|
|
/**
|
|
|
|
* @const {number}
|
|
|
|
*/
|
|
|
|
const FOO = 1
|
|
|
|
```
|
|
|
|
|
2017-10-29 15:56:20 +00:00
|
|
|
### Typedef
|
2016-09-26 09:56:33 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* A song
|
|
|
|
* @typedef {Object} Song
|
|
|
|
* @property {string} title - The title
|
|
|
|
* @property {string} artist - The artist
|
|
|
|
* @property {number} year - The year
|
|
|
|
*/
|
2017-10-29 12:04:52 +00:00
|
|
|
```
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
```js
|
2016-09-26 09:56:33 +00:00
|
|
|
/**
|
|
|
|
* Plays a song
|
|
|
|
* @param {Song} song - The {@link Song} to be played
|
|
|
|
*/
|
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
function play(song) {}
|
2016-09-26 09:56:33 +00:00
|
|
|
```
|
|
|
|
|
2020-08-03 12:27:34 +00:00
|
|
|
See: <https://jsdoc.app/tags-typedef.html>
|
2016-09-26 09:56:33 +00:00
|
|
|
|
2019-10-01 05:29:36 +00:00
|
|
|
### Typedef Shorthand
|
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
{% raw %}
|
|
|
|
|
2019-10-01 05:29:36 +00:00
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* A song
|
|
|
|
* @typedef {{title: string, artist: string, year: number}} Song
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
{% endraw %}
|
|
|
|
|
2019-10-01 05:29:36 +00:00
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* Plays a song
|
|
|
|
* @param {Song} song - The {@link Song} to be played
|
|
|
|
*/
|
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
function play(song) {}
|
2019-10-01 05:29:36 +00:00
|
|
|
```
|
|
|
|
|
2020-08-03 12:27:34 +00:00
|
|
|
See: <https://jsdoc.app/tags-typedef.html>
|
2019-10-01 05:29:36 +00:00
|
|
|
|
2019-03-23 23:34:48 +00:00
|
|
|
### Importing types
|
|
|
|
|
2019-01-10 14:33:55 +00:00
|
|
|
```js
|
|
|
|
/**
|
2019-03-23 23:34:48 +00:00
|
|
|
* @typedef {import('./Foo').default} Bar
|
2019-01-10 14:33:55 +00:00
|
|
|
*/
|
2019-03-23 23:34:48 +00:00
|
|
|
|
2019-01-10 14:33:55 +00:00
|
|
|
/**
|
|
|
|
* @param {Bar} x
|
|
|
|
*/
|
2019-03-23 23:34:48 +00:00
|
|
|
|
2020-06-22 14:38:08 +00:00
|
|
|
function test(x) {}
|
2019-01-10 14:33:55 +00:00
|
|
|
```
|
|
|
|
|
2019-03-23 23:34:48 +00:00
|
|
|
This syntax is [TypeScript-specific](https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript#import-types).
|
|
|
|
|
2018-05-20 12:45:28 +00:00
|
|
|
### Other keywords
|
2017-10-29 15:49:18 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
/**
|
|
|
|
* @throws {FooException}
|
2022-07-07 13:03:37 +00:00
|
|
|
* @async
|
2017-10-29 15:49:18 +00:00
|
|
|
* @private
|
|
|
|
* @deprecated
|
|
|
|
* @see
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
2020-08-01 14:08:38 +00:00
|
|
|
See the full list: <https://jsdoc.app/index.html#block-tags>
|
|
|
|
|
2017-10-29 12:04:52 +00:00
|
|
|
### Renaming
|
2016-09-26 09:56:33 +00:00
|
|
|
|
|
|
|
```js
|
2024-03-29 07:48:15 +00:00
|
|
|
/**
|
2016-09-26 09:56:33 +00:00
|
|
|
* @alias Foo.bar
|
|
|
|
* @name Foo.bar
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
2020-08-03 12:27:34 +00:00
|
|
|
Prefer `alias` over `name`. See: <https://jsdoc.app/tags-alias.html>
|