问题描述
有没有一种方法可以使JSDOC在函数内部显示变量而无需在函数之前使用 @namespace 批注?
Is there a way to have JSDOC to display variables inside of functions without using the @namespace annotation before the function?
我做了一个小的测试对象,但是它只会显示最后一个函数的内部变量 k ,该函数被声明为名称空间.我认为使用 @memberof!批注和精确的 @name 批注将在下面称为 diff 的第二种方法中显示内部变量.我正在使用-access"all" --explain 选项在命令上运行jsdoc3.
I have made a small test object, but it will only display the inner variable k for the last function, which is declared as a namespace. I thought using the @memberof! annotation and exact @name annotation would display the inner variable in the second method below called diff. I am running jsdoc3 on the command with the options --access "all" --explain.
这是测试对象的代码:
(function(){
"use strict";
/**
* @namespace
* @type {{}}
*/
window.myFunctions = {};
/**
* Return the sum
* @param {number} i
* @param {number} j
* @return {number}
*/
window.myFunctions.sum = function(i, j) {
/** @type {number} */
var k = i + j;
return k;
};
/**
* Return the difference i - j
* @param {number} i
* @param {number} j
* @return {number}
*/
window.myFunctions.diff = function(i, j) {
/**
* @inner
* @memberof! window.myFunctions.diff
* @type {number}
* @name window.myFunctions.diff~k
*/
var k = i - j;
return k;
};
/**
* Return the product
* @namespace
* @param {number} i
* @param {number} j
* @return {number}
*/
window.myFunctions.multiply = function(i, j) {
/** @type {number} */
var k = i * j;
return k;
}
});
推荐答案
从文档:
因此,您的代码示例可以像这样标记:
So, your code example could be marked up like this:
/**
* functions module.
* @module my/functions
*/
(function(){
"use strict";
/**
* @namespace
* @type {{}}
* @exports my/functions
* @name myFunctions
*/
window.myFunctions = {};
/**
* Return the sum
* @param {number} i
* @param {number} j
* @return {number}
* @exports my/functions
* @name sum
*/
window.myFunctions.sum = function(i, j) {
/**
* @type {number}
* @exports my/functions
* @name k
*/
var k = i + j;
return k;
};
/**
* Return the difference i - j
* @param {number} i
* @param {number} j
* @return {number}
* @exports my/functions
* @name diff
*/
window.myFunctions.diff = function(i, j) {
/**
* @inner
* @memberof! window.myFunctions.diff
* @type {number}
* @name window.myFunctions.diff~k
* @exports my/functions
*/
var k = i - j;
return k;
};
/**
* Return the product
* @namespace
* @param {number} i
* @param {number} j
* @return {number}
* @exports my/functions
* @name multiply
*/
window.myFunctions.multiply = function(i, j) {
/**
* @type {number}
* @exports my/functions
* @name k
*/
var k = i * j;
return k;
}
});
这篇关于JSDOC:如何记录函数的内部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!