javascript - 有没有办法使用 JsDoc 将函数标记为模板文字标记?
问题描述
模板字面量标签是特殊类型的函数,它以字符串数组作为第一个参数,然后是任意数量的占位符。当一个函数被定义为用于模板文字时,它通常仅用于该目的,因为它是一种非常特殊的函数形式。
是否有任何标签或首选方法可以使用 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."
解决方案
推荐阅读
- python - 添加列表元素
- node.js - 当堆栈跟踪对于标准输出来说太大时,如何获取 NodeJS 错误?
- c++ - Win32Api 窗口菜单激活问题
- dataframe - 我可以使用 DataFrames 在 Julia 中按天或按月分组吗
- python - 清理将每条记录视为表的数据集
- python - 从每个句子末尾的括号中的文本中提取日期
- python - is the connection/cursor object automatically closed in SQLAlchemy
- android - 如何更改 SearchView 的文本颜色?
- spring-boot - 间歇性 java.net.SocketException:来自服务器的文件意外结束
- amazon-cloudwatch - Cloudwatch 仪表板 - 从条形图中隐藏 x 轴标签