怎么来这个字符串
"answer
to life
the universe
and everything
is
#{40+2}
"
Run Code Online (Sandbox Code Playgroud)
汇编成
" answer to life the universe and everything is " + (40 + 2) + "";
Run Code Online (Sandbox Code Playgroud)
我如何强制coffescript保持多线(保持字符串插值完整):
"answer \
to life \
the universe \
and everything \
is \
"+(40+2)
Run Code Online (Sandbox Code Playgroud)
nzi*_*nab 75
尝试使用heredoc
语法:
myString = """
answer
to life
the universe
and everything
is
#{40+2}
"""
Run Code Online (Sandbox Code Playgroud)
这会转换为这个javascript:
var myString;
myString = "answer\nto life\nthe universe\nand everything\nis\n" + (40 + 2);
Run Code Online (Sandbox Code Playgroud)
实际上没有任何意义让它实际上是在视觉上编译的javascript中的换行符,是吗?
Han*_*ack 20
我同意在定义长字符串时能够保留缩进很好.您可以像在javascript中一样在coffeescript中使用字符串添加效果:
myVeryLongString = 'I can only fit fifty-nine characters into this string ' +
'without exceeding eighty characters on the line, so I use ' +
'string addition to make it a little nicer looking.'
Run Code Online (Sandbox Code Playgroud)
评估为
'I can only fit fifty-nine characters into this string without exceeding eighty characters, so I use string addition to make it a little nicer looking.'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20096 次 |
最近记录: |