使用 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?

http://img1.mukewang.com/6196068b0001cb6011101238.jpg

慕标5832272
浏览 207回答 1
1回答

牛魔王的故事

尝试:/**&nbsp;* Class representing a list of items.&nbsp;* */class List {&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Create a list.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; constructor(){&nbsp; &nbsp; &nbsp; &nbsp; this.items = [];&nbsp; &nbsp; }&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Add an item to the list.&nbsp; &nbsp; &nbsp;* @param {String} item - The name of the eitem.&nbsp; &nbsp; &nbsp;* @param {Number} qty - The number of items to add.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; add(item, qty) {&nbsp; &nbsp; &nbsp; &nbsp; var data = {item: item, qty: qty};&nbsp; &nbsp; &nbsp; &nbsp; this.items.push(data);&nbsp; &nbsp; }&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Return the list of items.&nbsp; &nbsp; &nbsp;* @return {Array.<{item: String, qty: Number}>} An array containing the items.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; getAll(){&nbsp; &nbsp; &nbsp; &nbsp; return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty}));&nbsp; &nbsp; }&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Delete a single item.&nbsp; &nbsp; &nbsp;* @param {Number} id - The index to be deleted.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; delete(id){&nbsp; &nbsp; &nbsp; &nbsp; this.items.splice(id, 1);&nbsp; &nbsp; }&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Return the number of items in the list.&nbsp; &nbsp; &nbsp;* @return {Number} The number of items.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; count(){&nbsp; &nbsp; &nbsp; &nbsp; return this.items.count;&nbsp; &nbsp; }}module.exports = {&nbsp; &nbsp; List};这是语法糖module.exports = {&nbsp; &nbsp; 'List': List};它将添加缺少的“列表”名称
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript