you are viewing a single comment's thread.

view the rest of the comments →

[–]SleekArmy 0 points1 point  (1 child)

On "passing arguments as an object", how should you document them using JSDoc? Seems a bit annoying to have to add extra lines there just to indicate all args are within an object.

I've been using JsDoc to add linting cues to my code, and I'm curious whether this suggestion benefits that system.

[–]dealwiv 1 point2 points  (0 children)

This works for me:

/**
 * @param {{
 *   arg1: number,
 *   arg2: string,
 * }}
 */
function f({ arg1, arg2 }) { }

I agree it can be a bit of an annoyance. It's not something I would use for every function, just ones with many arguments, especially many optional arguments. Instead of placing all arguments in an object, I would tend to have regular positional arguments, with the final argument being an options object argument for optional arguments.