【发布时间】:2016-10-26 07:42:49
【问题描述】:
我有一个长字符串,我使用 ES6 模板字符串构建它,但我希望它没有换行符:
var string = `As all string substitutions in Template Strings are JavaScript
expressions, we can substitute a lot more than variable names.
For example, below we can use expression interpolation to
embed for some readable inline math:`
console.log(string);
结果:
As all string substitutions in Template Strings are JavaScript
expressions, we can substitute a lot more than variable names.
For example, below we can use expression interpolation to
embed for some readable inline math:
我的期望:
As all string substitutions in Template Strings are JavaScript expressions, we can substitute a lot more than variable names. For example, below we can use expression interpolation to embed for some readable inline math:
【问题讨论】:
-
用斜杠 `\` 转义换行符,它会在输出中消失,即使在模板字符串中也是如此。
标签: javascript ecmascript-6 template-strings