How to document a method with multiple aliases?

谁说我不能喝 提交于 2019-12-06 07:52:19

The answer to this question may sound a bit funny but, actually, there is an official way to document method aliases, and they call it @borrows .

The @borrows tag allows you to add documentation for another symbol to your documentation.

This tag would be useful if you had more than one way to reference a function, but you didn't want to duplicate the same documentation in two places.

So, the getName() should be documented as follows:

Javascript code :

/**
 * 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 result :

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!