2013-05-11 109 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

相關問題