编程语言/JavaScript 注释规则:修订间差异
来自康健生活
< 编程语言
无编辑摘要 |
|||
| 第48行: | 第48行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| @ || 标签 || | | @ || 标签 || || <syntaxhighlight lang="javascript"> | ||
/** | /** | ||
* @param | * @param | ||
*/</syntaxhighlight> | */</syntaxhighlight> | ||
|- | |- | ||
| - || 说明文字 || | | - || 说明文字 || || <syntaxhighlight lang="javascript"> | ||
/** | /** | ||
* @param {string} name - 名字 | * @param {string} name - 名字 | ||
*/</syntaxhighlight> | */</syntaxhighlight> | ||
|- | |- | ||
| @module || 声明模块 || | | @module || 声明模块 || || | ||
|- | |- | ||
| @class || 声明类 || @class 必须搭配 @constructor 或 @static 使用 | | @class || 声明类 || || @class 必须搭配 @constructor 或 @static 使用 | ||
|- | |- | ||
| @constructor || 非静态类 || | | @constructor || 非静态类/构造函数声明注释 || || | ||
|- | |- | ||
| @static || 静态类 || | | @static || 静态类 || || | ||
|- | |- | ||
| @method || 声明函数 || | | @method || 声明函数 || || | ||
|- | |- | ||
| @for || 所属类名 || | | @for || 所属类名 || || | ||
|- | |- | ||
| @param {type}|| 声明函数参数 || <syntaxhighlight lang="javascript"> | | @param {type}|| 声明函数参数 || @arg/@argument || <syntaxhighlight lang="javascript"> | ||
/** | /** | ||
* @param {string} a - 必传参数 | * @param {string} a - 必传参数 | ||
| 第78行: | 第78行: | ||
function test(a, b, c) {}</syntaxhighlight> | function test(a, b, c) {}</syntaxhighlight> | ||
|- | |- | ||
| @property || 声明类属性 || | | @property || 声明类属性 || || | ||
|- | |- | ||
| @desc || 示例 || 示例 | | @desc || 示例 || || 示例 | ||
|- | |- | ||
| @ | | @returns || 示例 || @return || 示例 | ||
|- | |- | ||
| @ | | @desc/@description || 示例 || || 示例 | ||
|- | |- | ||
| @ | | @author || 示例 || || 示例 | ||
|- | |- | ||
| @ | | @file/@overview || 代码文件的描述 || || 示例 | ||
|- | |- | ||
| @copyright || | | @copyright || 代码的版权信息 || || 示例 | ||
|- | |- | ||
| @createDate || 示例 || 示例 | | @createDate || 示例 || || 示例 | ||
|- | |- | ||
| @default || 示例 || 示例 | | @default || 示例 || || 示例 | ||
/** | |||
* {@link https://github.com GitHub}. | |||
*/</syntaxhighlight> | |||
|- | |||
| @example || 示例注释 || || 示例 | |||
|- | |||
| @license || 文件许可证 || || 示例 | |||
|- | |||
| @callback || 描述回调函数 || || 示例 | |||
|- | |||
| @this || 关键字的指向 || || <syntaxhighlight lang="javascript"> | |||
/** | |||
* // @this <namePath> | |||
* @this Greeter | |||
*/</syntaxhighlight> | |||
|- | |- | ||
| @ | | @throws || 说明可能会被抛出的错误 || @exception || <syntaxhighlight lang="javascript"> | ||
/** | /** | ||
* { | * // @throws free-form description | ||
* // @throws {<type>} | |||
* // @throws {<type>} free-form description | |||
* @throws {InvalidArgumentException} | |||
* @throws Will throw an error if the argument is null. | |||
* @throws {DivideByZero} Argument x must be non-zero. | |||
*/</syntaxhighlight> | */</syntaxhighlight> | ||
|- | |- | ||
| | | @todo || 记录一个将要完成的任务 || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // @todo text describing thing to do. | |||
* @todo Write the documentation. | |||
*/</syntaxhighlight> | |||
|- | |- | ||
| | | @type || 记录一个对象的类型 || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // @type {type name} | |||
* @type {(string|Array.<string>)} | |||
* @type {number} | |||
*/</syntaxhighlight> | |||
|- | |- | ||
| | | @typedef || 记录一个自定义的类型 || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // @typedef [<type>] <namepath> | |||
*/ | |||
// 定义了一个联合类型的参数,表示可以包含数字或字符串 | |||
/** | |||
* A number, or a string containing a number. | |||
* @typedef {(number|string)} NumberLike | |||
*/ | |||
/** | |||
* Set the magic number. | |||
* @param {NumberLike} x - The magic number. | |||
*/ | |||
function setMagicNumber(x) { | |||
} | |||
// 定义了一个更复杂的类型,一个对象的几个属性,并设置其namepath | |||
/** | |||
* The complete Triforce, or one or more components of the Triforce. | |||
* @typedef {Object} WishGranter~Triforce | |||
* @property {boolean} hasCourage - Indicates whether the Courage component is present. | |||
* @property {boolean} hasPower - Indicates whether the Power component is present. | |||
* @property {boolean} hasWisdom - Indicates whether the Wisdom component is present. | |||
*/ | |||
/** | |||
* A class for granting wishes, powered by the Triforce. | |||
* @class | |||
* @param {...WishGranter~Triforce} triforce - One to three {@link WishGranter~Triforce} objects | |||
* containing all three components of the Triforce. | |||
*/ | |||
function WishGranter() {}</syntaxhighlight> | |||
|- | |- | ||
| | | @variation || 区分具有相同名称的不同的对象 || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // @variation <variation number> | |||
* @variation 6 | |||
*/</syntaxhighlight> | |||
|- | |- | ||
| | | @version || 版本 || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // @version <version number> | |||
* @version 0.0.1 | |||
*/</syntaxhighlight> | |||
|} | |||
内链 | |||
{| class="wikitable" | |||
|- | |- | ||
! name !! description !! alias !! eq | |||
|- | |- | ||
| | | @link || 链接到文档中的另一个项目 || @linkcode/@linkplain || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // {@link <namepath or URL>} | |||
* // [link text]{@link <namepath or URL>} | |||
* // {@link <namepath or URL>|<link text>} | |||
* // {@link <namepath or URL> <link text>} | |||
* See {@link MyClass} | |||
* See [MyClass's foo property]{@link MyClass#foo} | |||
* See {@link https://kangkk.com} | |||
* See {@link https://kangkk.com|kangkk} | |||
* See {@link https://kangkk.com kangkk} | |||
*/ | |||
# {@linkcode}:强制使用等宽字体链接文本。 | |||
# {@linkplain}:强制显示为正常的文本,没有等宽字体链接文本。</syntaxhighlight> | |||
|- | |- | ||
| | | @tutorial || 链接到一个教程(创建一个链接到您指定的教程标识符) || || <syntaxhighlight lang="javascript"> | ||
/** | |||
* // {@tutorial <tutorial ID>} | |||
* // [link text]{@tutorial <tutorial ID>} | |||
* // {@tutorial <tutorial ID>|<link text>} | |||
* // {@tutorial <tutorial ID> <link text>} | |||
* See {@tutorial dashboard} | |||
* See [Configuring the Dashboard]{@tutorial dashboard} | |||
* See {@tutorial dashboard|Configuring the Dashboard} | |||
* See {@tutorial dashboard Configuring the Dashboard} | |||
*/</syntaxhighlight> | |||
|} | |} | ||
2022年3月21日 (一) 07:57的版本
引言
常用
/**
* @FileOverview 文件概述
* @Author kangkk(kangjian@360.cn)
* @Date 2021
* @Last Modified by: kangjian
* @Last Modified time: 2022-03-4 16:56:00
* @version 1.0.0
*/
文件注释
注释包括以下信息:
- 概要说明及版本
- 项目地址
- 版权声明
- 开源协议
- 版本号
- 修改时间(ISO 格式)
/*!
* ...
*/
普通注释
//
// this is comment
TODO
某段代码有功能未实现,或者有待完善,必须添加 TODO 标记
// TODO ...
/* */
/*
...
*/
文档注释
/**
* ...
*/
可选参数
| @ | 标签 | /**
* @param
*/
| |
| - | 说明文字 | /**
* @param {string} name - 名字
*/
| |
| @module | 声明模块 | ||
| @class | 声明类 | @class 必须搭配 @constructor 或 @static 使用 | |
| @constructor | 非静态类/构造函数声明注释 | ||
| @static | 静态类 | ||
| @method | 声明函数 | ||
| @for | 所属类名 | ||
| @param {type} | 声明函数参数 | @arg/@argument | /**
* @param {string} a - 必传参数
* @param {number} [b=2] - 参数有默认值
* @param {number} [c] - 可选参数
*/
function test(a, b, c) {}
|
| @property | 声明类属性 | ||
| @desc | 示例 | 示例 | |
| @returns | 示例 | @return | 示例 |
| @desc/@description | 示例 | 示例 | |
| @author | 示例 | 示例 | |
| @file/@overview | 代码文件的描述 | 示例 | |
| @copyright | 代码的版权信息 | 示例 | |
| @createDate | 示例 | 示例 | |
| @default | 示例 | 示例
/** * {@link https://github.com GitHub}.
*/</syntaxhighlight>
| |
| @example | 示例注释 | 示例 | |
| @license | 文件许可证 | 示例 | |
| @callback | 描述回调函数 | 示例
| |
| @this | 关键字的指向 | /**
* // @this <namePath>
* @this Greeter
*/
| |
| @throws | 说明可能会被抛出的错误 | @exception | /**
* // @throws free-form description
* // @throws {<type>}
* // @throws {<type>} free-form description
* @throws {InvalidArgumentException}
* @throws Will throw an error if the argument is null.
* @throws {DivideByZero} Argument x must be non-zero.
*/
|
| @todo | 记录一个将要完成的任务 | /**
* // @todo text describing thing to do.
* @todo Write the documentation.
*/
| |
| @type | 记录一个对象的类型 | /**
* // @type {type name}
* @type {(string|Array.<string>)}
* @type {number}
*/
| |
| @typedef | 记录一个自定义的类型 | /**
* // @typedef [<type>] <namepath>
*/
// 定义了一个联合类型的参数,表示可以包含数字或字符串
/**
* A number, or a string containing a number.
* @typedef {(number|string)} NumberLike
*/
/**
* Set the magic number.
* @param {NumberLike} x - The magic number.
*/
function setMagicNumber(x) {
}
// 定义了一个更复杂的类型,一个对象的几个属性,并设置其namepath
/**
* The complete Triforce, or one or more components of the Triforce.
* @typedef {Object} WishGranter~Triforce
* @property {boolean} hasCourage - Indicates whether the Courage component is present.
* @property {boolean} hasPower - Indicates whether the Power component is present.
* @property {boolean} hasWisdom - Indicates whether the Wisdom component is present.
*/
/**
* A class for granting wishes, powered by the Triforce.
* @class
* @param {...WishGranter~Triforce} triforce - One to three {@link WishGranter~Triforce} objects
* containing all three components of the Triforce.
*/
function WishGranter() {}
| |
| @variation | 区分具有相同名称的不同的对象 | /**
* // @variation <variation number>
* @variation 6
*/
| |
| @version | 版本 | /**
* // @version <version number>
* @version 0.0.1
*/
|
内链
| name | description | alias | eq |
|---|---|---|---|
| @link | 链接到文档中的另一个项目 | @linkcode/@linkplain | /**
* // {@link <namepath or URL>}
* // [link text]{@link <namepath or URL>}
* // {@link <namepath or URL>|<link text>}
* // {@link <namepath or URL> <link text>}
* See {@link MyClass}
* See [MyClass's foo property]{@link MyClass#foo}
* See {@link https://kangkk.com}
* See {@link https://kangkk.com|kangkk}
* See {@link https://kangkk.com kangkk}
*/
# {@linkcode}:强制使用等宽字体链接文本。
# {@linkplain}:强制显示为正常的文本,没有等宽字体链接文本。
|
| @tutorial | 链接到一个教程(创建一个链接到您指定的教程标识符) | /**
* // {@tutorial <tutorial ID>}
* // [link text]{@tutorial <tutorial ID>}
* // {@tutorial <tutorial ID>|<link text>}
* // {@tutorial <tutorial ID> <link text>}
* See {@tutorial dashboard}
* See [Configuring the Dashboard]{@tutorial dashboard}
* See {@tutorial dashboard|Configuring the Dashboard}
* See {@tutorial dashboard Configuring the Dashboard}
*/
|
No categories