我可以在JSDOC里面有variables吗?

我有几个函数共享一些基础的数据结构,同时也做了非常不同的事情,抽象并不是一个好主意。

文档可能看起来像这样(尽pipe这只是一个小示例,许多方法仅共享一些文档):

/** * Creates an array of objects, with each object containing the average distance that minute. The * objects have the keys **Timestamp** (ms since epoch), **Year** (year in device local time) **Month** ( * month in device local time), **Day** (day in device local time), **Hour** (hour in device local time) * **Season** (season in device local time, Northern Hemisphere), **Weekday** (Week day name in device * local time), **WeekNum** (week number (1-53) in device local time), **Depth** (the average depth that * minute), and **Vibration** (the magnitude of the maximum acceleration for the minute, in Gs). * <snip> */ /** * Creates an array of objects, with each object containing the data for one minute of temperature data * from temperature probes. The objects have the keys **Timestamp** (ms since epoch), **Year** (year in * device local time) **Month** (month in device local time), **Day** (day in device local time), **Hour** * (hour in device local time) **Season** (season in device local time, Northern Hemisphere), **Weekday** * (Week day name in device local time), **WeekNum** (week number (1-53) in device local time), * **Temperature** (Temperature measured by the temperature probe), **Vib**(the standard deviation of the * acceleration of the accelerometer, in Gs). * <snip> */ 

从样本中可以看出,我对振动的logging以及它的含义是不一致的。 我不想每次修改文档的时候都去修复这些文档(甚至更糟的是,硬件工程师改变它的含义)。 有没有办法让我有一个全球性的术语词典,并酌情插入它? 就像是:

 terms.json > {vibDef: "the magnitude of the maximum acceleration for the minute, in Gs"} code.js > /** * Creates an array of objects, with each object containing the average distance that minute. The * objects have the keys **Timestamp** (ms since epoch), **Year** (year in device local time) **Month** ( * month in device local time), **Day** (day in device local time), **Hour** (hour in device local time) * **Season** (season in device local time, Northern Hemisphere), **Weekday** (Week day name in device * local time), **WeekNum** (week number (1-53) in device local time), **Depth** (the average depth that * minute), and **Vibration** (<<vibDef>>). * <snip> */ 

这将插入我的定义vibDef无处不在文档string中find?

感谢@ssube的build议,我写了一个扩展文本写在!><!之间的插件<! 进入更长的定义,保存在全局文件中。 为了logging,这里是:

 var globalDict = require('../globals.js').jsDoc; exports.handlers = { beforeParse: function(e) { var reg = /!>(?=\S)(\w+)(?=\S)<!/; do { m = reg.exec(e.source); if (m) { var originalTxt = m[0]; var expandedDef = globalDict[m[1]]; if (expandedDef) { e.source = e.source.replace(originalTxt, expandedDef); } else { e.source = e.source.replace(originalTxt, m[1]); // Prevent infinite loop console.log('Error: Missing definition for jsDoc keyword', m[1]); } } } while (m); } }; 

globals.js看起来像:

 exports.jsDoc = { vibration: "twice the standard deviation in the recorded acceleration over the course of a minute" };