将长模板文字行包装为多行而不在字符串中创建新行 [英] Wrap long template literal line to multiline without creating a new line in the string
本文介绍了将长模板文字行包装为多行而不在字符串中创建新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 es6 模板文字中,如何将长模板文字包装成多行而不在字符串中创建新行?
In es6 template literals, how can one wrap a long template literal to multiline without creating a new line in the string?
例如,如果您这样做:
const text = `a very long string that just continues
and continues and continues`
然后它将为字符串创建一个新行符号,将其解释为有一个新行.如何在不创建换行符的情况下将长模板文字包装成多行?
Then it will create a new line symbol to the string, as interpreting it to have a new line. How can one wrap the long template literal to multiple lines without creating the newline?
推荐答案
如果你引入了 line continuation () 在文字中的换行符处,它不会在输出上创建换行符:
If you introduce a line continuation () at the point of the newline in the literal, it won't create a newline on output:
const text = `a very long string that just continues
and continues and continues`;
console.log(text); // a very long string that just continuesand continues and continues
这篇关于将长模板文字行包装为多行而不在字符串中创建新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文