From 40b3b1e0537e2ce9a8bb4bccb13b467e4f816b97 Mon Sep 17 00:00:00 2001 From: Zongyi Zheng Date: Mon, 7 Aug 2017 10:07:08 +0800 Subject: [PATCH] add example of documenting destructuring parameters (#177) Fixes: https://github.com/jsdoc3/jsdoc3.github.com/issues/159 Refs: https://github.com/jsdoc3/jsdoc/issues/987 --- content/en/tags-param.md | 17 +++++++++++++++++ tags-param.html | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/content/en/tags-param.md b/content/en/tags-param.md index af271c4c..1d82b3d0 100644 --- a/content/en/tags-param.md +++ b/content/en/tags-param.md @@ -107,6 +107,23 @@ Project.prototype.assign = function(employee) { ``` {% endexample %} +If a parameter is destructured without an explicit name, you can give the object an appropriate one and +document its properties. + +{% example "Documenting a destructuring parameter" %} +```js +/** + * 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 }) { + // ... +}; +``` +{% endexample %} + You can also combine this syntax with JSDoc's syntax for array parameters. For example, if multiple employees can be assigned to a project: diff --git a/tags-param.html b/tags-param.html index 7d6df394..11eafc5c 100644 --- a/tags-param.html +++ b/tags-param.html @@ -127,8 +127,19 @@

Parameters with properties

Project.prototype.assign = function(employee) { // ... }; - - + +

If a parameter is destructured without an explicit name, you can give the object an appropriate one and document its properties.

+
+
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 }) {
+    // ...
+};
+

You can also combine this syntax with JSDoc's syntax for array parameters. For example, if multiple employees can be assigned to a project:

Documenting properties of values in an array
/**