【发布时间】:2018-08-28 20:58:55
【问题描述】:
我主要从 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 的任何人,我希望这是有道理的。
【问题讨论】:
-
也许您可以使用此插件将至少示例移动到源文件之外:github.com/jugglinmike/jsdoc-external-example
-
啊,这很酷。谢谢!但这当然还没有真正解决问题
-
你可以在任何地方制作jsdoc cmets。如果它们不是紧邻函数或方法,解析器本身无法知道它是一个函数,因此您可以在独立注释中添加
@function <function name>标签。 -
@garlon4 您介意添加一个答案,并举个例子。我似乎无法让这个想法发挥作用。
标签: javascript jsdoc