如何在常规字符串上调用模板文字标记功能? [英] How Can I Call a Template Literal Tag Function on a Regular String?
本文介绍了如何在常规字符串上调用模板文字标记功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有模板文字标签功能 foo
,让我来做:
If I have a template literal tag function foo
, which let's me do:
const fooTaggedText = foo`some text`;
我是否可以以某种方式在常规字符串上调用该标记?例如:
is it possible for me to somehow call that tag on a regular string? For instance:
// This doesn't actually work
const fooTaggedText = foo('some text');
推荐答案
我不确定是否知道,但是
I'm not sure if I got it, but wouldn't this work?
const taggedText = str => foo`${str}`;
因此,您可以像这样使用它:
So you'd use it like:
taggedText('my string')
// foo`my string`
如果有帮助,请提供代表:)
Please give some rep if it helps :)
这篇关于如何在常规字符串上调用模板文字标记功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文