Skip to content

Commit 40b3b1e

Browse files
zhengzongyihegemonic
authored andcommitted
add example of documenting destructuring parameters (#177)
Fixes: #159 Refs: jsdoc/jsdoc#987
1 parent 5505441 commit 40b3b1e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

content/en/tags-param.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ Project.prototype.assign = function(employee) {
107107
```
108108
{% endexample %}
109109

110+
If a parameter is destructured without an explicit name, you can give the object an appropriate one and
111+
document its properties.
112+
113+
{% example "Documenting a destructuring parameter" %}
114+
```js
115+
/**
116+
* Assign the project to an employee.
117+
* @param {Object} employee - The employee who is responsible for the project.
118+
* @param {string} employee.name - The name of the employee.
119+
* @param {string} employee.department - The employee's department.
120+
*/
121+
Project.prototype.assign = function({ name, department }) {
122+
// ...
123+
};
124+
```
125+
{% endexample %}
126+
110127
You can also combine this syntax with JSDoc's syntax for array parameters. For example, if multiple
111128
employees can be assigned to a project:
112129

tags-param.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,19 @@ <h3 id="parameters-with-properties">Parameters with properties</h3>
127127
Project.prototype.assign = function(employee) {
128128
// ...
129129
};
130-
</code></pre>
131-
</figure>
130+
</code></pre></figure>
131+
<p>If a parameter is destructured without an explicit name, you can give the object an appropriate one and document its properties.</p>
132+
<figure>
133+
<figcaption>Documenting a destructuring parameter</figcaption><pre class="prettyprint lang-js"><code>/**
134+
* Assign the project to an employee.
135+
* @param {Object} employee - The employee who is responsible for the project.
136+
* @param {string} employee.name - The name of the employee.
137+
* @param {string} employee.department - The employee's department.
138+
*/
139+
Project.prototype.assign = function({ name, department }) {
140+
// ...
141+
};
142+
</code></pre></figure>
132143
<p>You can also combine this syntax with JSDoc&#39;s syntax for array parameters. For example, if multiple employees can be assigned to a project:</p>
133144
<figure>
134145
<figcaption>Documenting properties of values in an array</figcaption><pre class="prettyprint lang-js"><code>/**

0 commit comments

Comments
 (0)