如何记录具有多个别名的方法?
How to document a method with multiple aliases?
我正在尝试记录以下 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- It tells JSDoc to rename the method.
2- It can't be used for multiple aliases.
是否有任何官方方式来记录这些方法?
这个问题的答案可能听起来有点好笑,但实际上,有一种官方方法可以记录方法别名,他们称之为 @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.
因此,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 结果:
我正在尝试记录以下 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- It tells JSDoc to rename the method.
2- It can't be used for multiple aliases.
是否有任何官方方式来记录这些方法?
这个问题的答案可能听起来有点好笑,但实际上,有一种官方方法可以记录方法别名,他们称之为 @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.
因此,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 结果: