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.