最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用JSDoc到文档模块导出类

IT培训 admin 6浏览 0评论

使用JSDoc到文档模块导出类

CommonJS模块中的简单类具有以下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;
    }

}

[生成文档时,我丢失了类的名称。而不是被称为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
};

它将添加缺少的“列表”名称

使用JSDoc到文档模块导出类

CommonJS模块中的简单类具有以下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;
    }

}

[生成文档时,我丢失了类的名称。而不是被称为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
};

它将添加缺少的“列表”名称

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论