这个字符串怎么来的
"answer
to life
the universe
and everything
is
#{40+2}
"
编译成
" answer to life the universe and everything is " + (40 + 2) + "";
如何强制 coffescript 保持多行(保持字符串插值完整):
"answer \
to life \
the universe \
and everything \
is \
"+(40+2)
最佳答案
尝试使用 heredoc
语法:
myString = """
answer
to life
the universe
and everything
is
#{40+2}
"""
这将转换为以下 JavaScript:
var myString;
myString = "answer\nto life\nthe universe\nand everything\nis\n" + (40 + 2);
实际上没有任何意义让它在编译后的 JavaScript 中以视觉方式出现在换行符上,不是吗?
关于CoffeeScript 多行字符串编译为多行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19389174/