Jsdoc:如何使用括号符号记录属性
jsdoc: how to document properties using bracket notation?
给定这个相当愚蠢的函数,应该如何为"range"参数编写文档?
/**
* @param {number} value
* @param {Object} range
* @param {number} range['<']
* @param {number} range['<=']
* @param {number} range['>']
* @param {number} range['>=']
*/
function testIsInRange(value, range) {
var threshold;
if ((threshold = range['<'], threshold !== undefined) && !(value < threshold)) {
fail('Value must be less than ' + threshold);
}
if ((threshold = range['<='], threshold !== undefined) && !(value <= threshold)) {
fail('Value must be less than or equal to ' + threshold);
}
if ((threshold = range['>'], threshold !== undefined) && !(value > threshold)) {
fail('Value must be greater than ' + threshold);
}
if ((threshold = range['>='], threshold !== undefined) && !(value >= threshold)) {
fail('Value must be greater than or equal to ' + threshold);
}
}
点和括号似乎都不起作用。可以识别属性类型(Object和number),但不能识别它们的名称。
类型可以指定为复杂对象:
/**
* @param {number} value
* @param {{'<': number, '<=': number, '>': number, '>=': number}} range
*/
function testIsInRange(value, range) {
...
}
或者,解构也可以提供帮助,尽管它需要将参数重命名为非符号名称:
/**
* @param {number} value
* @param {number} lt
* @param {number} lte
* @param {number} gt
* @param {number} gte
*/
function testIsInRange(value, {'<':lt, '<=':lte, '>':gt, '>=':gte}) {
...
}
相关文章:
- 使用Dnamics CRM 2011中的JavaScript读取子网格的所有记录,而不考虑活动页面
- 在.csv文件中写入学位符号
- 使用相同的数据集绘制各种符号
- AngularJs对所有页面中的所有记录进行排序
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- window.location替换并传递URL历史记录条目中的变量
- Javascript历史记录转换为php行
- JavaScript,PHP-用JavaScript将多个数据库记录发送到变量或表
- 猫鼬在特定记录中查找嵌套记录
- 浏览器何时记录历史记录
- 将带点符号的属性(有时)传递给函数
- RegEx JavaScript:数字后的符号提取
- 将一个表的id与另一个表中的user_id进行匹配,以获取mysql中的记录
- 更新成员数据模型中的记录列表
- 如何使用提交按钮搜索表中的记录
- 正在OrientDB中嵌入函数中的记录
- 如何在计算器符号为零时替换它
- 使用Rails 3中的AJAX删除记录
- 如何在JSDoc中记录深度大于2的符号
- Jsdoc:如何使用括号符号记录属性