Skip to content

Commit 5b6b3bb

Browse files
monkbroctmcw
authored andcommitted
docs: Update recipe for documenting destructuring parameters
1 parent 3472aa2 commit 5b6b3bb

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

docs/RECIPES.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,30 @@ function addTheXandYProperties({ x, y }) {
8787
}
8888
```
8989

90-
Destructured parameters are **unnamed**: while we have names for x & y,
91-
the function doesn't declare what it will call the object you call
92-
this function with. So documentation.js names your destructured parameters
93-
for you: if the param is the first, it'll call it `$0`, if second, `$1`,
94-
and so on.
90+
Destructured parameters are **unnamed** in the code: while we have names
91+
for x & y, the function doesn't declare what it will call the object you
92+
call this function with. So you must name the parent object of
93+
destructured parameters to document them in documentation.js.
9594

9695
So, if you want to add more detailed documentation for properties
97-
within destructured params, prefix property names with $0 for the object,
98-
or $1 if it's the second parameter, and so on - the number is the position
99-
of the destructuring parameter within the list of parameters. Here's
100-
an example:
96+
within destructured params, name the parent object, then prefix property
97+
names with the parent object. Here's an example:
10198

10299
```js
103100
/**
104-
* This method has partially inferred params
105-
* @param {String} $0.fishes number of kinds of fish
101+
* This method has hierachical params
102+
* @param {Object} animals different kinds of animals
103+
* @param {String} animals.fishes number of kinds of fish
106104
*/
107105
function fishesAndFoxes({ fishes, foxes }) {
108106
return fishes + foxes;
109107
}
110108
```
111109

110+
Note: documentation.js used to implicitly call those parent objects
111+
`$0`, `$1`, etc. Starting in documentation.js 4.0.0-rc.1 the more
112+
explicit syntax is required.
113+
112114
## Object Factories
113115

114116
Libraries like [d3](http://d3js.org/) eschew JavaScript's `new` operator

0 commit comments

Comments
 (0)