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

问题描述 投票:0回答:1

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

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;
}

如您所见, getName() 方法有两个别名( getN()getFullName() ),因此明显要使用的标签是 @alias 标签,但不幸的是,它有两个别名主要问题:

1- 它告诉 JSDoc 重命名该方法。

2- 它不能用于多个别名

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

javascript documentation jsdoc jsdoc3
1个回答
4
投票

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

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

如果您有 不止一种方法来引用某个内容,则此标签将会很有用 function,但您不想在中重复相同的文档 两个地方。

因此,getName() 应记录如下:

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 结果:

© www.soinside.com 2019 - 2024. All rights reserved.