Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting JS function which takes an object as an argument

In dynamic languages like JavaScript or PHP it is common practise to pass only one argument to the function. This argument is an object which encapsulate all options. What is the best way of documenting these options with ScriptDoc (or similar)?

like image 387
ciembor Avatar asked Mar 25 '26 07:03

ciembor


1 Answers

Using JSDoc it can be done as follows:

/**
 * @param {Object} o       Object containing function params.
 * @param {String} o.bar   Example String param.
 * @param {Number} o.baz   Example Number param.
 */
function foo(o) {
}

More information can be found in the Parameters with Properties section of JSDoc's TagParam documentation.

like image 111
jabclab Avatar answered Mar 26 '26 21:03

jabclab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!