重要 ES6 代码的文档示例
Documentation examples for non-trivial ES6 code
我正在努力寻找合适的文档 samples/references 来记录 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 组件时有效,但在编写实用程序函数等时用处不大。在 React 之外。
没关系,我刚刚意识到 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 }) {
// ...
};
我正在努力寻找合适的文档 samples/references 来记录 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 组件时有效,但在编写实用程序函数等时用处不大。在 React 之外。
没关系,我刚刚意识到 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 }) {
// ...
};