@@ -187,17 +187,36 @@ <h3>Synonyms</h3>
187
187
< h3 > Overview</ h3 >
188
188
189
189
< p >
190
- The @param tag (or @arg or @argument) documents a parameter of a function.
190
+ The @param tag (or @arg or @argument) documents a function parameter.
191
+ </ p >
192
+
193
+ < p >
194
+ The @param tag requires you to specify the name of the parameter you are documenting. You can also
195
+ include the parameter's type, enclosed in curly brackets, and a description of the parameter.
196
+ </ p >
197
+
198
+ < p >
199
+ The parameter type can be a built-in JavaScript type, such as < code > string</ code > or
200
+ < code > Object</ code > , or a < a href ="about-namepaths.html "> JSDoc namepath</ a > to another symbol in
201
+ your code. If you have written documentation for the symbol at that namepath, JSDoc will
202
+ automatically link to the documentation for that symbol. You can also use a type expression to
203
+ indicate, for example, that a parameter is not nullable or can accept any type; see the
204
+ < a href ="tags-type.html "> @type documentation</ a > for details.
205
+ </ p >
206
+
207
+ < p >
208
+ If you provide a description, you can make the JSDoc comment more readable by inserting a hyphen
209
+ before the description. Be sure to include a space before and after the hyphen.
191
210
</ p >
192
211
193
212
< h3 > Examples</ h3 >
194
213
195
214
< p >
196
- The following examples show the basic usage of @param.
215
+ The following examples show how to include names, types, and descriptions in a @param tag .
197
216
</ p >
198
217
199
218
< dl class ="example ">
200
- < dt > Basic usage of @param </ dt >
219
+ < dt > Name only </ dt >
201
220
< dd >
202
221
< pre class ="prettyprint lang-js ">
203
222
/**
@@ -210,7 +229,7 @@ <h3>Examples</h3>
210
229
</ pre >
211
230
</ dd >
212
231
</ dl > < dl class ="example ">
213
- < dt > Using a type with @param </ dt >
232
+ < dt > Name and type</ dt >
214
233
< dd >
215
234
< pre class ="prettyprint lang-js ">
216
235
/**
@@ -223,11 +242,29 @@ <h3>Examples</h3>
223
242
</ pre >
224
243
</ dd >
225
244
</ dl > < dl class ="example ">
226
- < dt > Using type and description with @param</ dt >
245
+ < dt > Name, type, and description</ dt >
246
+ < dd >
247
+ < pre class ="prettyprint lang-js ">
248
+ /**
249
+ * @param {string} somebody Somebody's name.
250
+ */
251
+ function sayHello(somebody) {
252
+ alert('Hello ' + somebody);
253
+ }
254
+
255
+ </ pre >
256
+ </ dd >
257
+ </ dl > < p >
258
+ You can add a hyphen before the description to make it more readable. Be sure to include a space
259
+ before and after the hyphen.
260
+ </ p >
261
+
262
+ < dl class ="example ">
263
+ < dt > Name, type, and description, with a hyphen before the description</ dt >
227
264
< dd >
228
265
< pre class ="prettyprint lang-js ">
229
266
/**
230
- * @param {string} somebody Name
267
+ * @param {string} somebody - Somebody's name.
231
268
*/
232
269
function sayHello(somebody) {
233
270
alert('Hello ' + somebody);
@@ -236,15 +273,15 @@ <h3>Examples</h3>
236
273
</ pre >
237
274
</ dd >
238
275
</ dl > < p >
239
- The following examples show how to indicate that a parameter can be optional and has a default value
276
+ The following examples show how to indicate that a parameter is optional and has a default value.
240
277
</ p >
241
278
242
279
< dl class ="example ">
243
- < dt > An optional parameter</ dt >
280
+ < dt > An optional parameter (using JSDoc syntax) </ dt >
244
281
< dd >
245
282
< pre class ="prettyprint lang-js ">
246
283
/**
247
- * @param {string} [somebody] Name
284
+ * @param {string} [somebody] - Somebody's name.
248
285
*/
249
286
function sayHello(somebody) {
250
287
if (!somebody) {
@@ -256,11 +293,28 @@ <h3>Examples</h3>
256
293
</ pre >
257
294
</ dd >
258
295
</ dl > < dl class ="example ">
259
- < dt > Optional parameter and default value </ dt >
296
+ < dt > An optional parameter (using Google Closure Compiler syntax) </ dt >
260
297
< dd >
261
298
< pre class ="prettyprint lang-js ">
262
299
/**
263
- * @param {String} [somebody=John Doe] Name
300
+ * @param {string=} somebody - Somebody's name.
301
+ */
302
+ function sayHello(somebody) {
303
+ if (!somebody) {
304
+ somebody = 'John Doe';
305
+ }
306
+ alert('Hello ' + somebody);
307
+ }
308
+
309
+
310
+ </ pre >
311
+ </ dd >
312
+ </ dl > < dl class ="example ">
313
+ < dt > An optional parameter and default value</ dt >
314
+ < dd >
315
+ < pre class ="prettyprint lang-js ">
316
+ /**
317
+ * @param {string} [somebody=John Doe] - Somebody's name.
264
318
*/
265
319
function sayHello(somebody) {
266
320
if (!somebody) {
@@ -272,16 +326,18 @@ <h3>Examples</h3>
272
326
</ pre >
273
327
</ dd >
274
328
</ dl > < p >
275
- A parameter could also have several types instead of just one. It can also be used multiple times.
276
- The following examples reflect these situations.
329
+ The following examples show how to use type expressions to indicate that a parameter can accept
330
+ multiple types (or any type), and that a parameter can be provided more than once. See the
331
+ < a href ="tags-type.html "> @type documentation</ a > for details about the type expressions that JSDoc
332
+ supports.
277
333
</ p >
278
334
279
335
< dl class ="example ">
280
- < dt > Multiple types </ dt >
336
+ < dt > Allows one type OR another type (type union) </ dt >
281
337
< dd >
282
338
< pre class ="prettyprint lang-js ">
283
339
/**
284
- * @param {String|Array } [somebody=John Doe] Name or array of names
340
+ * @param {(string|string[]) } [somebody=John Doe] - Somebody's name, or an array of names.
285
341
*/
286
342
function sayHello(somebody) {
287
343
if (!somebody) {
@@ -295,51 +351,70 @@ <h3>Examples</h3>
295
351
</ pre >
296
352
</ dd >
297
353
</ dl > < dl class ="example ">
298
- < dt > Variable parameter</ dt >
354
+ < dt > Allows any type</ dt >
355
+ < dd >
356
+ < pre class ="prettyprint lang-js ">
357
+ /**
358
+ * @param {*} somebody - Whatever you want.
359
+ */
360
+ function sayHello(somebody) {
361
+ console.log('Hello ' + JSON.stringify(somebody));
362
+ }
363
+
364
+ </ pre >
365
+ </ dd >
366
+ </ dl > < dl class ="example ">
367
+ < dt > Allows a parameter to be repeated</ dt >
299
368
< dd >
300
369
< pre class ="prettyprint lang-js ">
301
370
/**
302
371
* Returns the sum of all numbers passed to the function.
303
- * @param {...Number } num A positive or negative number
372
+ * @param {...number } num - A positive or negative number.
304
373
*/
305
374
function sum(num) {
306
- var i= 0, n= arguments.length, t= 0;
307
- for (; i<n; i++) {
375
+ var i = 0, n = arguments.length, t = 0;
376
+ for (; i < n; i++) {
308
377
t += arguments[i];
309
378
}
310
379
return t;
311
380
}
312
381
313
382
</ pre >
314
383
</ dd >
315
- </ dl > < dl class ="example ">
316
- < dt > Parameters that are callbacks</ dt >
384
+ </ dl > < p >
385
+ If a parameter accepts a callback function, you can use the < a href ="tags-callback.html "> @callback
386
+ tag</ a > to define a callback type, then include the callback type in the @param tag.
387
+ </ p >
388
+
389
+ < dl class ="example ">
390
+ < dt > Parameters that accept a callback</ dt >
317
391
< dd >
318
392
< pre class ="prettyprint lang-js ">
319
393
/**
320
- * Does something asynchronously, calling the callback on completion.
394
+ * This callback type is called `requestCallback` and is displayed as a global symbol.
395
+ *
396
+ * @callback requestCallback
397
+ * @param {number} responseCode
398
+ * @param {string} responseMessage
399
+ */
400
+
401
+ /**
402
+ * Does something asynchronously and executes the callback on completion.
321
403
* @param {requestCallback} cb - The callback that handles the response.
322
404
*/
323
405
function doSomethingAsynchronously(cb) {
324
406
// code
325
407
};
326
408
327
- /**
328
- * This callback is displayed as a global member.
329
- * @callback requestCallback
330
- * @param {number} responseCode
331
- * @param {string} responseMessage
332
- */
333
-
334
409
</ pre >
335
410
</ dd >
336
411
</ dl > < h3 > See Also</ h3 >
337
412
338
413
< ul >
414
+ < li > < a href ="tags-callback.html "> @callback</ a > </ li >
339
415
< li > < a href ="tags-returns.html "> @returns</ a > </ li >
340
416
< li > < a href ="tags-type.html "> @type</ a > </ li >
341
417
< li > < a href ="tags-typedef.html "> @typedef</ a > </ li >
342
- < li > < a href ="tags-callback.html "> @callback</ a > </ li >
343
418
</ ul >
344
419
345
420
</ article >
0 commit comments