语法
🌐 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:
/**
* Generate numbers in the Fibonacci sequence.
*
* @generator
* @function fibonacci
* @yields {number} The next number in the Fibonacci sequence.
*/