为了账号安全,请及时绑定邮箱和手机立即绑定

使用 JSDoc 记录模块导出类

使用 JSDoc 记录模块导出类

慕标5832272 2021-11-18 15:53:23
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?
查看完整描述

1 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

尝试:


/**

 * 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

};

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


查看完整回答
反对 回复 2021-11-18
  • 1 回答
  • 0 关注
  • 206 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信