Synonyms
const
语法
¥Syntax
@constant [<type> <name>]
概述
¥Overview
@constant 标签用于将文档标记为属于常量符号。
¥The @constant tag is used to mark the documentation as belonging to a symbol that is a constant.
示例
¥Examples
在此示例中,我们正在记录一个字符串常量。请注意,虽然代码使用了 const
关键字,但 JSDoc 并不要求这样做。如果你的 JavaScript 宿主环境尚不支持常量声明,则 @const 文档可以同样有效地用于 var
声明。
¥In this example we are documenting a string constant. Note that although the code is using the
const
keyword, this is not required by JSDoc. If your JavaScript host environment doesn't yet
support constant declarations, the @const documentation can just as effectively be used on var
declarations.
/** @constant
@type {string}
@default
*/
const RED = 'FF0000';
/** @constant {number} */
var ONE = 1;
请注意,该示例在 @type 标记中提供了类型。这是可选的。此外,这里也使用了可选的 @default 标签,这会自动将分配的值(例如 'FF0000')添加到文档中。
¥Note that the example provides the type in a @type tag. This is optional. Also the optional @default tag is used here too, this will automatically add whatever the assigned value is (for example 'FF0000') to the documentation.