coffeescript多行字符串编译为多行字符串

coffeescript多行字符串编译为多行字符串,coffeescript,Coffeescript,这根绳子怎么会这样 "answer to life the universe and everything is #{40+2} " 汇编成 " answer to life the universe and everything is " + (40 + 2) + ""; 如何强制coffescript保持多行(保持字符串插值完整): 尝试使用herdoc语法: myString = """ answer to life the universe and

这根绳子怎么会这样

"answer 
 to life 
 the universe 
 and everything
 is
 #{40+2}
"
汇编成

"  answer   to life   the universe   and everything  is  " + (40 + 2) + "";
如何强制coffescript保持多行(保持字符串插值完整):


尝试使用
herdoc
语法:

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);
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.'

在编译后的javascript中,让它实际出现在换行符上并没有任何意义,是吗?

我同意,在定义长字符串时能够保持缩进是很好的。您可以在coffeescript中使用字符串添加来实现此效果,就像在javascript中一样:

var myString;

myString = "answer\nto life\nthe universe\nand everything\nis\n" + (40 + 2);
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.'
评估为

'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.'

不,我希望它们在javascript中出现在新的行中。。。似乎很有趣impossible@Agzam:为什么您关心生成的JavaScript是什么样子?这些东西不是供人类使用的。是的,这有什么关系?我在处理xml字符串。手动将现有javascript代码转换为咖啡,并尝试比较结果。。。而且很难比较当你将javascript转换成coffeescript时,编译后的js看起来几乎不会一样——试图区分它们是徒劳的。同样,将js逐字复制到coffeescript通常只会导致糟糕的coffeescript。你通常可以用咖啡更优雅地做事。如果您真的想将遗留的js转换成coffeescript(并且不想只使用“适当的”coffeescript技术编写),您可以使用类似的工具。我不确定这与XML字符串有什么关系。