使用 JSDoc 记录模块导出 class
Using JSDoc to document module exporting class
CommonJS 模块中的简单 class 具有以下 JSDoc 注释:
/**
* Class representing a list of items.
* */
module.exports = class List {
/**
* Create a list.
*/
constructor(){
this.items = [];
}
/**
* Add an item to the list.
* @param {String} item - The name of the eitem.
* @param {Number} qty - The number of items to add.
*/
add(item, qty) {
var data = {item: item, qty: qty};
this.items.push(data);
}
/**
* Return the list of items.
* @return {Array.<{item: String, qty: Number}>} An array containing the items.
*/
getAll(){
return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty}));
}
/**
* Delete a single item.
* @param {Number} id - The index to be deleted.
*/
delete(id){
this.items.splice(id, 1);
}
/**
* Return the number of items in the list.
* @return {Number} The number of items.
*/
count(){
return this.items.count;
}
}
当我生成文档时,我丢失了 class 的名称。它没有被称为 List,而是被标记为 exports,请参见下面的屏幕截图。如何使该工具将模块正确标记为 List?
试试:
/**
* Class representing a list of items.
* */
class List {
/**
* Create a list.
*/
constructor(){
this.items = [];
}
/**
* Add an item to the list.
* @param {String} item - The name of the eitem.
* @param {Number} qty - The number of items to add.
*/
add(item, qty) {
var data = {item: item, qty: qty};
this.items.push(data);
}
/**
* Return the list of items.
* @return {Array.<{item: String, qty: Number}>} An array containing the items.
*/
getAll(){
return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty}));
}
/**
* Delete a single item.
* @param {Number} id - The index to be deleted.
*/
delete(id){
this.items.splice(id, 1);
}
/**
* Return the number of items in the list.
* @return {Number} The number of items.
*/
count(){
return this.items.count;
}
}
module.exports = {
List
};
它是
的语法糖
module.exports = {
'List': List
};
它将添加缺少的 'List' 名称
CommonJS 模块中的简单 class 具有以下 JSDoc 注释:
/**
* Class representing a list of items.
* */
module.exports = class List {
/**
* Create a list.
*/
constructor(){
this.items = [];
}
/**
* Add an item to the list.
* @param {String} item - The name of the eitem.
* @param {Number} qty - The number of items to add.
*/
add(item, qty) {
var data = {item: item, qty: qty};
this.items.push(data);
}
/**
* Return the list of items.
* @return {Array.<{item: String, qty: Number}>} An array containing the items.
*/
getAll(){
return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty}));
}
/**
* Delete a single item.
* @param {Number} id - The index to be deleted.
*/
delete(id){
this.items.splice(id, 1);
}
/**
* Return the number of items in the list.
* @return {Number} The number of items.
*/
count(){
return this.items.count;
}
}
当我生成文档时,我丢失了 class 的名称。它没有被称为 List,而是被标记为 exports,请参见下面的屏幕截图。如何使该工具将模块正确标记为 List?
试试:
/**
* Class representing a list of items.
* */
class List {
/**
* Create a list.
*/
constructor(){
this.items = [];
}
/**
* Add an item to the list.
* @param {String} item - The name of the eitem.
* @param {Number} qty - The number of items to add.
*/
add(item, qty) {
var data = {item: item, qty: qty};
this.items.push(data);
}
/**
* Return the list of items.
* @return {Array.<{item: String, qty: Number}>} An array containing the items.
*/
getAll(){
return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty}));
}
/**
* Delete a single item.
* @param {Number} id - The index to be deleted.
*/
delete(id){
this.items.splice(id, 1);
}
/**
* Return the number of items in the list.
* @return {Number} The number of items.
*/
count(){
return this.items.count;
}
}
module.exports = {
List
};
它是
的语法糖module.exports = {
'List': List
};
它将添加缺少的 'List' 名称