2013-05-11 114 views
0

假设我有在CoffeeScript的文件这一功能如何在IDEA中将函数作为参数传递给多行数组?

test = (arr, fn) -> 
    console.log item for item in arr 
    fn() 

这是我如何把它

test [1, 2, 3, 4, 5], -> 
    console.log "start" 
    # function body 
    console.log "finish" 

一切OK,直到阵列变得太长,我想拆它几行。像这样

test ["first element here", 
     "second element here", 
     "third element here", 
     "fourth element here", 
     "fifth element here"], -> 
    console.log "start" 
    # function body 
    console.log "finish" 

这是有效的,因为CoffeeScript的编译器编译它正是我期待的,但IDEA说有在console.log "start"线意外缩进。我按按Ctrl + Alt + L和IDEA给了我这个

test ["first element here", 
     "second element here", 
     "third element here", 
     "fourth element here", 
     "fifth element here"], -> 
console.log "start" 
# function body 
console.log "finish" 

这是不对的,因为在这种情况下,空函数作为参数传递。这是一个错误还是我可以自己修复它?

+1

我觉得你应该把它报告给的IntelliJ的CoffeeScript插件团队:) – Ven 2013-05-11 11:11:05

+0

是的,我已经openned问题 – 2013-05-11 13:56:42

回答

1

JetBrains公司的支持对我说,这是一个错误,所以我openned一个issue here

0

也许你不得不缩进函数体多一点点,使其工作:

test ["first element here", 
     "second element here", 
     "third element here", 
     "fourth element here", 
     "fifth element here"], -> 
     console.log "start" 
     # function body 
     console.log "finish" 
#      ^ This column is indented two from the start of the array 
#    ^ Array starts here 

至少在的IntelliJ为我工作。

+0

尝试按Ctrl清理你的代码+ Alt + L键 – 2013-05-11 13:23:19

+0

@Vitalii我想你想一个解决办法对于* *意外缩进**也作为答案。 – maba 2013-05-11 15:41:27

+0

我使用清理功能很多,在这种情况下,我不能使用它,因为它打破了我的代码。 – 2013-05-11 16:00:01

0

可能是CoffeeScript IDEA插件中的一个bug,因为user1737909 mentioned

但是,如果你现在要解决这个权利,我建议只使用一个变量数组,并继续前进:

arr = [ 
    "first element here" 
    "second element here" 
    "third element here" 
    "fourth element here" 
    "fifth element here" 
] 

test arr, -> 
    console.log "start" 
    # function body 
    console.log "finish" 
+0

这只是一个黑客,而不是真正的解决方案 – 2013-05-11 13:20:09

+0

@VitaliiKorsakov,它不是解决IDEA抱怨代码的问题吗?此外,我不会说让代码更容易阅读(对于人类和IDE来说似乎都是这样),但是对于每一个它自己= P – epidemian 2013-05-12 00:53:14

相关问题