如何记录具有多个别名的方法?

2023-12-24

我正在尝试记录获取名称()以下 Person 构造函数的方法:

JavaScript 代码:

/**
 * Creates a person instance.
 * @param {string} name The person's full name.
 * @constructor
 */
function Person( name ) {

    /**
     * Returns the person's full name.
     * @return {string} The current person's full name.
     */
    function getName() {
        return name;
    }

    this.getName = getName;
    this.getN = getName;
    this.getFullName = getName;
}

如您所见,获取名称()方法有两个别名(getN() and 获取全名()),所以明显要使用的标签是@alias http://usejsdoc.org/tags-alias.html标签,但不幸的是,它有两个主要问题:

1-它告诉 JSDocrename方法。

2-它不能用于多个别名.

有没有官方的方法来记录这些方法?


这个问题的答案可能听起来有点有趣,但实际上,有一种官方方法来记录方法别名,他们称之为@borrows http://usejsdoc.org/tags-borrows.html .

The @borrows标签允许您添加另一个符号的文档 你的文档。

如果您有此标签将会很有用不止一种方式来引用 功能,但您不想在中重复相同的文档 两个地方。

So, the 获取名称()应记录如下:

JavaScript 代码:

/**
 * Creates a person instance.
 * @param {string} name The person's full name.
 * @constructor
 * @borrows Person#getName as Person#getN
 * @borrows Person#getName as Person#getFullName
 */
function Person( name ) {

    /**
     * Returns the person's full name.
     * @return {string} The current person's full name.
     * @instance
     * @memberof Person
     */
    function getName() {
        return name;
    }

    this.getName = getName;
    this.getN = getName;
    this.getFullName = getName;
}

JSDoc 结果:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何记录具有多个别名的方法? 的相关文章