You can specify the type of a parameter like following:
/**
* Adds a user
* @param {String} name the name of the user
* @param {Number} age the age of the user
* @return {Boolean} true if successful
*/
##
# Adds a user
# @param {String} name the name of the user
# @param {Number} age the age of the user
# @return {Boolean} true if successful
The result of the above comment:
Adds a user
Name | Type | Description |
---|---|---|
name | String | the name of the user |
age | Number | the age of the user |
Name | Type | Description |
---|---|---|
(Returns) | Boolean | true if successful |
Often, JavaScript functions have an options object. You can add a comment for this like following:
/**
* Defines a new property on an object.
* @param {Object} object the object on which to define the property
* @param {String} name the name of the property to be defined
* @param {Object} descriptor the descriptor for the property
* @param {Boolean} [descriptor.configurable=false] true if and only if the type of this property descriptor may be changed
* @param [descriptor.value=undefined] the value associated with the property
*/
##
# Defines a new property on an object.
# @param {Object} object the object on which to define the property
# @param {String} name the name of the property to be defined
# @param {Object} descriptor the descriptor for the property
# @param {Boolean} [descriptor.configurable=false] true if and only if the type of this property descriptor may be changed
# @param [descriptor.value=undefined] the value associated with the property
The result of the above comment:
Defines a new property on an object.
Name | Type | Description |
---|---|---|
object | Object | the object on which to define the property |
name | String | the name of the property to be defined |
descriptor | Object | the descriptor for the property |
configurable=false optional | Boolean | true if and only if the type of this property descriptor may be changed |
value=undefined optional | the value associated with the property |
(Nothing) |
Currently, options can be nested at the maximum third levels. (eg. user.name.first_name)
Using callback is the common pattern of JavaScript, especially in Node.js. You can add a comment for this like following:
/**
* Asynchronous file open
* @param {String} path the path to open
* @param {String} flags flags for opening
* @param {Number|String} [mode='0666'] file creation mode
* @param {Function} [callback] the callback function
* @param {Error} callback.error not null if an error is occurred
* @param {Number} callback.fd a file descriptor
*/
##
# Asynchronous file open
# @param {String} path the path to open
# @param {String} flags flags for opening
# @param {Number|String} [mode='0666'] file creation mode
# @param {Function} [callback] the callback function
# @param {Error} callback.error not null if an error is occurred
# @param {Number} callback.fd a file descriptor
The result of the above comment:
Asynchronous file open
Name | Type | Description |
---|---|---|
path | String | the path to open |
flags | String | flags for opening |
mode='0666' optional | Number, String | file creation mode |
callback optional | Function(error, fd) | the callback function |
error | Error | not null if an error is occurred |
fd | Number | a file descriptor |
(Nothing) |