【问题标题】:Documentation examples for non-trivial ES6 code [duplicate]重要的 ES6 代码的文档示例 [重复]
【发布时间】:2018-04-29 23:09:44
【问题描述】:

我正在努力寻找适合 ES6 代码的文档示例/参考,例如某种 ES6 文档的备忘单。

我想与 JSDoc 文档保持一致,但是在这个问题的最常见答案中,我只能设法找到 琐碎 代码文档,而不是适合新 ES6+/React 语法的文档或更复杂的参数,如数组、映射、参数反序列化等。

例如does-javascript-have-a-standard-for-commenting-functions 仅提供有关具有标准参数的常规 JS 函数的文档示例。

我想找到记录此类内容的规则/好方法,如何指示需要或不需要的参数等。

我想记录的方法示例

const signInWithCredentials = ({ emails, password, authentication_code }, options) => {

}

我能想到这样的事情

**
 * Attempts sign in with any possible credentials pair
 * (Provide either email + password, or an authentication_code and a provider name in the options
 * @param { 
 *   emails: { Array<String> },
 *   password: { String },
 *   authentication_code: { String }
 * } - credentials
 * @param { Object } - options
 * @param { String } - options.provider

但我不太确定如何处理没有名称 function({ param1, param2 })、嵌套 function({ param1: { nestedParam1, nestedParam2 }) 或重命名为 function({ param1: name1 }) 的反序列化参数,以及如何处理组合类型,如 xxx 数组

我已经将PropTypes 用于几个方法声明,但它们仅在使用 React 组件时有效,但在编写实用程序函数等时不太有用。

【问题讨论】:

    标签: javascript reactjs ecmascript-6 jsdoc ecmascript-2016


    【解决方案1】:

    没关系,我刚刚意识到 JSDoc 有一个包含文档示例的官方页面,其中包含关于解构的部分

    http://usejsdoc.org/tags-param.html

    Documenting a destructuring parameter
    /**
     * Assign the project to an employee.
     * @param {Object} employee - The employee who is responsible for the project.
     * @param {string} employee.name - The name of the employee.
     * @param {string} employee.department - The employee's department.
     */
    Project.prototype.assign = function({ name, department }) {
        // ...
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      相关资源
      最近更新 更多