我发现文档的following是JSDoc中的可选参数。
/**
* @param {string} [somebody=John Doe] - Somebody's name.
*/
function sayHello(somebody) {
if (!somebody) {
somebody = 'John Doe';
}
alert('Hello ' + somebody);
}
和文档参数对象属性。
/**
* 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(employee) {
// ...
};
现在我希望文档在JSDoc中是必需的对象参数。像这样的东西。:
/**
* Assign the project to an employee.
* @param {Object} employee - The employee who is responsible for the project.
* @param {string} employee.name=John Doe - The name of the employee.
* @param {string} employee.department - The employee's department.
*/
Project.prototype.assign = function(employee) {
// ...
};
我该怎么做?
也许解决方案@param {string} employee.name=John Doe - The name of the employee.
已经是正确的了?
答案 0 :(得分:2)
你是对的。根据{{3}}中的“具有属性的参数”:
如果预期参数具有特定属性,则可以通过提供额外的@param标记来记录该属性。
但是,如果您要在其他功能中重复使用这些属性,则可能需要定义Employee
类型:
/**
* The employee who is responsible for the project
* @typedef {Object} Employee
* @property {string} name - The name of the employee
* etc.
*/
/*
* @param {Employee} employee - The employee who is responsible for the project.
*/
Project.prototype.assign = function(employee) {