我正在尝试使用 JSDoc3 记录一些旧代码,并且我一直试图让它在文档中包含实例方法的参数 - 或者根本将任何东西显示为实例属性。我怀疑问题是代码不遵循在 javascript 中伪造类的预期习语,但我想在开始重写任何内容之前记录所有内容。我试图用实际代码的结构来做一个问题的小例子:
/**
* Global function
* @param {Object} v Stuff that they're trying to avoid making global
* @return {Object} Updated v
*/
jsdoc_test = function( v ) {
/**
* Some stuff is defined in this namespace
* @namespace space
*/
var space = {};
/**
* Something that acts like a class
* @name space.someclass
* @memberOf space
* @constructor
* @type {function}
* @param {any} y blah blah
* @return {Object} The constructed object
*/
space.someclass = function( w ) {
var obj = {
source: w, // might need this again
derived: foo( w ), // what we usually need
etc: "etc" // and so on
};
/**
* This should be a member function, but it appears as a static property
* @name space.someclass.methodA
* @memberOf space.someclass
* @type {function}
* @instance
* @param {any} x Parameters do not appear in documentation
* @return {Object} this
*/
obj.methodA = function( x ) {
bar( x ); // or whatever methodA does
return this;
}
/**
* This should be a member function, but it doesn't show up at all
* @name space.someclass.methodB
* @memberOf space.someclass#
* @type {function}
* @param {any} y Parameters do not appear in documentation
* @return {Object} this
*/
obj.methodB = function( y ) {
baz( y ); // or whatever methodB does
return this;
}
return obj;
/**
* This should be a member function, but it doesn't show up at all
* @name space.someclass.methodC
* @memberOf space.someclass.prototype
* @type {function}
* @param {any} z Parameters do not appear in documentation
* @return {Object} this
*/
obj.methodC = function( z ) {
qux( z ); // or whatever methodC does
return this;
}
return obj;
}
// ...
}
我希望所有三种方法都作为实例方法出现在生成的文档中。实际上,methodA
显示为静态属性,而methodB
and methodC
(遵循此处的建议)根本不出现
如何让 JSDoc3 记录实例方法及其参数,而无需重写代码?