JSDoc 中文网

语法

¥Syntax

@generator

概述

¥Overview

@generator 标记表示函数是 生成器函数,这意味着它是使用语法 function* foo() {} 声明的。此标签在 JSDoc 3.5.0 及更高版本中可用。

¥The @generator tag indicates that a function is a generator function, meaning that it was declared using the syntax function* foo() {}. This tag is available in JSDoc 3.5.0 and later.

一般来说,你不需要使用这个标签,因为 JSDoc 会自动检测生成器函数并在生成的文档中识别它们。但是,如果你正在为代码中未出现的生成器函数编写虚拟注释,则可以使用此标记告诉 JSDoc 该函数是生成器函数。

¥In general, you do not need to use this tag, because JSDoc automatically detects generator functions and identifies them in the generated documentation. However, if you are writing a virtual comment for a generator function that does not appear in your code, you can use this tag to tell JSDoc that the function is a generator function.

示例

¥Example

以下示例显示了使用 @generator 标签的虚拟注释:

¥The following example shows a virtual comment that uses the @generator tag:

带有@generator 标签的虚拟评论
/**

 * Generate numbers in the Fibonacci sequence.

 *  * @generator

 * @function fibonacci

 * @yields {number} The next number in the Fibonacci sequence.
 */