如何在JSDoc的@param注释中引用另一个@param参数?
Can I reference the first @param definition in the second @param statement in JSDoc?
当然可以!在JSDoc里,你完全可以在第二个@param的描述中引用第一个参数的定义,用{@link}标签就能轻松实现这个需求。
举个修改后的示例给你看,这样写就能让item参数的描述关联到array参数的定义:
/** * Another way to call array.includes(item); * @param {Array} array The array to check for the presence of the target item * @param {*} item The element to test if contained in {@link array} * @returns {boolean} Returns true if the item exists in the array, false otherwise */ function hasQ(array, item) {return array.includes(item);}
小细节说明:
- 这里的
{@link array}会直接关联到同一个函数注释里第一个@param定义的array参数,主流IDE(比如VS Code)在你鼠标悬停这个引用时,会自动显示array参数的描述信息,让你的注释逻辑更连贯。 - 如果是在更复杂的场景(比如跨函数、跨模块引用),你可以写更完整的引用路径,比如
{@link module:yourModule.hasQ.array},但在同一个函数的注释里,直接写参数名就足够清晰了。
内容的提问来源于stack exchange,提问作者SumNeuron
相关产品推荐
相关产品推荐

