如何让JSDoc记录我的_methods?

时间:2011-10-10 20:52:04

标签: javascript documentation jsdoc

我有一个包含此方法的类

/**
* Uses the native RegExp object and the native string.replace to replace text
* @name _replace
* @param {String} find Text string or regex to search for
* @param {String} replace Text string or regex for replacing
* @param {String} string   String to perfom the replace on
* @returns {String} Returns the string with the text replaced
*/  
this._replace = function(find, replace, str) {
    var regex;

    if(typeof find !== undefined && replace !== undefined && typeof str === 'string') {
        regex = new RegExp(find, this._getFlags()); 
        return str.replace(regex, replace, str);            
    } else {
        return false;
    }

};

它以_为前缀,以区别于公共接口的replace方法。为什么JSDoc在前面有_时不记录这个方法?如果我删除它,它会完美记录。有什么办法可以让JSDoc记录这个方法吗?

1 个答案:

答案 0 :(得分:4)

jsdoc-toolkit假定以_开头的方法是私有的。这确实是一个普遍的惯例。您可以通过使用--private选项运行来查看该方法。

要强制将其记录为公开,请添加@public代码。

顺便说一句,您不需要使用@name,在大多数情况下会自动检测到某个功能的名称。