如何使用 JSDoc 命名参数

Nal*_*ish 1 javascript json function jsdoc

在我的一个 JavaScript 文件中,我必须引入一些可选参数,因此我遵循了指南并得到了以下方法声明:

function my_func({
    opt1,
    opt2 = 250,
    opt3 = "A message.",
    opt4 = null
}) {
    // Do something
}
Run Code Online (Sandbox Code Playgroud)

我可以这样称呼它:

my_func({
        opt1: "boom",
        opt4: document.getElementById("some-element"),
        opt3: "A different message.",
        opt2: 200
    });
Run Code Online (Sandbox Code Playgroud)

我什至可以删除一些参数并将它们按任何顺序排列。
现在,我想使用 JSDoc 对其进行记录,但我很困惑我的 JSDoc 注释会是什么样子?因为这应该定义我必须在大括号内输入参数,并且我还必须使用键。

如果有任何其他方式可以使用命名参数和/或可选参数,那么也将不胜感激。

foo*_*red 6

另一种选择是命名单个参数并指定其子参数

/**
 * my func has a single object argument
 * @param {Object} params
 * @param {string} params.opt1  - opt1 description
 * @param {number} [params.opt2=250] - opt2 description
 * @param {string} [params.opt3='A message'] - opt3 description
 * @param {Element|null} [params.opt4=null] - opt4 description
 */
function my_func({
  opt1,
  opt2 = 250,
  opt3 = "A message",
  opt4 = null
}) {
  // Do something
}
Run Code Online (Sandbox Code Playgroud)