我主要从 Angular 的角度提出这个问题(但任何建议都会有帮助)。我的函数上有 JSDoc,但它使代码看起来非常混乱。我只是想知道是否有办法将 JSDoc 移动到某种类型的外部文件。
我的 JSDoc 的一个例子:
/**
* Does a GET call on the service MyGetCall
* @param {string} pUserID - 1st Parameter: User Login ID
* @param {string} pPassword - 2nd Parameter: User Password
* @returns The Call's Http Observable (subscribe to this function).
* @example this.flowservice.MyGetCall('Johnny', 'MySuperSecretPassword')
* .subscribe(response => {
* console.log(response)
* });
*/
MyGetCall(pUserID: string, pPassword: string): Observable<any> {
const temp = this.httpclient.get<JSON>(`http://XXX/MyGetCall?userid=${pUserID}&password=${pPassword}`, {headers: this.headers});
return temp;
}
因此,在这个示例中,我想删除所有 JSDoc 并将其放入某种外部文件(jsdocs.xxx)中。该文件将如下所示:
MyGetCall:
/**
* Does a GET call on the service MyGetCall
* @param {string} pUserID - 1st Parameter: User Login ID
* @param {string} pPassword - 2nd Parameter: User Password
* @returns The Call's Http Observable (subscribe to this function).
* @example this.flowservice.MyGetCall('Johnny', 'MySuperSecretPassword')
* .subscribe(response => {
* console.log(response)
* });
*/
MyOtherFunction:
...
MyOtherOtherFunction:
...
然后我可以将此文件 (jsdocs.xxx) 导入某处,以便它与我的应用程序一起使用。对于任何使用过 JSDoc 的人来说,我希望这是有意义的。
如果,内联,我会记录一个类方法,如下所示:
/**
* @class
* @alias fileReader
*/
function fileReader() {
/**
* Tells the caller if it can handle the given file by returning a boolean.
*
* @param {File} file A `File` object.
* @returns {boolean} `true` if this reader can read a file.
*/
this.canRead = function (file) {
...
};
}
相反,我可以在其他地方记录我的方法:
/**
* @class
* @alias fileReader
*/
function fileReader() {
this.canRead = function (file) {
...
};
}
并且文档可以位于不同的文件中,如下所示:
/**
* Tells the caller if it can handle the given file by returning a boolean.
*
* @function canRead
* @memberof fileReader
* @instance
* @param {File} file A `File` object.
* @returns {boolean} `true` if this reader can read a file.
*/
The @function
如果 jsdoc 后面没有紧跟着实际的函数,则参数定义函数的名称。这@memberof
告诉它父类或命名空间。这@instance
说它是一种需要实例化类的方法。
对于你的例子,我猜文档是
/**
* Does a GET call on the service MyGetCall
* @function MyGetCall
* @memberof flowservice
* @instance
* @param {string} pUserID - 1st Parameter: User Login ID
* @param {string} pPassword - 2nd Parameter: User Password
* @returns The Call's Http Observable (subscribe to this function).
* @example this.flowservice.MyGetCall('Johnny', 'MySuperSecretPassword')
* .subscribe(response => {
* console.log(response)
* });
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)