CoffeeScript:意外的INDENT错误 [英] CoffeeScript : unexpected INDENT error

查看:231
本文介绍了CoffeeScript:意外的INDENT错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Rails 3.1应用程序中试用CoffeeScript。但是,我无法让
弄清楚如何在CoffeeScript中打破长行,而不会出现
以上的错误

I am trying out CoffeeScript in my Rails 3.1 app. However, I am not able to figure out how to break long lines in CoffeeScript without getting the above error

例如,如何/何地您会打破下面的代码行吗?

For example, how/where would you break the following line of code

alert x for x in [1,2,3,4,5]  when x > 2

如果您想要类似的东西

alert x for
  x in [1,2,3,4,5]
  when x > 2

在我的vimrc中,我设置了

In my vimrc, I have set

 ts=2, sw=2 and I expand tabs. 

但是,我无法获得像上面这样简单的代码才能正常工作。

And yet, I cannot get something as simple as the line above to work properly.

我的Gemfile.lock显示了带有coffee-script-source 1.1.3的coffee-script-2.2.0

My Gemfile.lock shows coffee-script-2.2.0 with coffee-script-source 1.1.3

推荐答案

如果您的理解力太长,可以使用@brandizzi提到的 \ 来打破它,但是我认为您可能会只需在有意义的地方使用理解并在不知道的地方扩展到常规代码,便会更好:

If you have a comprehension that is too long you can break it with \ as @brandizzi mentions, but I think you might have better luck just using comprehensions where they make sense and expanding to 'regular' code where they don't:

alert x for x in [1,2,3,4,5]  when x > 2

...可以重写为...

...can be rewritten as...

for x in [1,2,3,4,5]
  alert x if x > 2

...甚至...

for x in [1,2,3,4,5]
  if x > 2
    alert x

换句话说,理解力是简短,简洁的摘要的语法糖-您不必将它们用于所有操作。

In other words, comprehensions are syntactic sugar for short, concise snippets - you don't have to use them for everything.

这篇关于CoffeeScript:意外的INDENT错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆