问题描述
如果我有模板文字标签功能foo
,让我来做:
const fooTaggedText = foo`some text`;
我可以以某种方式在常规字符串上调用该标签吗?例如:
// This doesn't actually work
const fooTaggedText = foo('some text');
解决方法
我不确定是否知道,但这行不通吗?
const taggedText = str => foo`${str}`;
因此,您可以像这样使用它:
taggedText('my string')
// foo`my string`
如果有帮助,请提供代表:)