我試圖用JSDoc3記錄一些舊代碼,並且我試圖讓它在文檔中包含實例方法的參數 - 或者將任何東西顯示爲實例屬性。我懷疑問題在於代碼沒有遵循在javascript中僞造類的預期習慣用法,但我想在我開始重寫任何內容之前將所有內容都記錄下來。我試圖使問題的一個小例子,與實際代碼的結構:jsdoc:如何獲取實例方法參數?
/**
* 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
和methodC
(其遵循here建議)完全不
我怎麼JSDoc3記錄實例方法,與它們的參數出現,而無需重寫代碼?
你嘗試記錄'VAR OBJ = ...''通過/ ** * @class /?這樣,你應該能夠正確地引用它來添加屬性或返回值。 – SGD
根據http://usejsdoc.org/tags-class.html,「@ class」是「@ constructor」的同義詞,我已經在應用於工廠功能。用'@ class'替換'@ constructor'和/或將註釋塊移到對象上對生成的文檔沒有影響。該類已經作爲一個類出現在文檔中,問題是實例方法顯示爲靜態屬性。 – ShadSterling
是的,但你不記錄'obj'。我的建議是通過'@class'在函數內部記錄'obj',然後引用該內部類作爲函數的返回值.. – SGD