2012-06-30 18 views

回答

1
nextPos = services.indexOf('times'); 

這是JS,但在CoffeeScript中也是有效的。但是請注意,如果在CofeeScript之外使用,那麼它是ECMA5的補充,因此在舊版瀏覽器中不起作用(編輯 - 如評論所述,這當然意味着IE < = 8)。

+1

更具體地說,它不能在IE 8及以下版本中使用。 [參考](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf) –

+0

真棒謝謝你們 –

+0

我會'nextPost = services.indexOf'times''使它更CS- esque – hvgotcodes

1

基於Utkanos的答案,但在CS:

getNext = (arr, key) -> 
    arr[arr.indexOf(key) + 1] 
console.log getNext services, 'times' # food