ciembor
ciembor

Reputation: 7337

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)?

Upvotes: 3

Views: 148

Answers (1)

jabclab
jabclab

Reputation: 15042

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.

Upvotes: 3

Related Questions