是否可以使用JsDoc将功能标记为模板文字标记?

时间:2018-08-03 17:35:00

标签: javascript ecmascript-6 documentation jsdoc template-literals

Template literal tags是特殊类型的函数,它们将字符串数组作为第一个参数,并将其后的任意数量的占位符作为参数。当定义一个函数用于模板文字时,由于它是一种非常特定的函数形式,因此通常仅用于此目的。

是否有任何标记或首选方法使用JsDoc标记功能?

以下是此类功能的示例:

/**
 * What goes here?
 */
function withoutWhiteSpace(strings, ...placeholders) {
  let withSpace = strings.reduce((result, string, i) => (
    result + placeholders[i - 1] + string
  ));
  let withoutSpace = withSpace.replace(/\s\s+/g, ' ');
  return withoutSpace;
}

let lines = 3;
let exampleString = withoutWhiteSpace`This is a string created with the template
    literal syntax. It's really long and stretches over ${lines} lines, so a tag
    is used to remove line breaks and whitespace.`
// exampleString = "This is a string created with the template literal syntax. It's really long and stretches over 3 lines, so a tag is used to remove line breaks and whitespace."

0 个答案:

没有答案