Instead of
((i) ->
//Do something with i
)(annoying.and.complicated[variable].name[5])
You can write
do (i=annoying.and.complicated[variable].name[5]) ->
//Do something with i
Also, I always have these two functions in scope.
after = (ms,cb) -> setTimeout(cb,ms)
every = (ms,cb) -> setInterval(cb,ms)
Which makes formulating your example trivial
for i in [1..5]
do (i) ->
after i*1000, ->
console.log i
Or even:
for i in [1..5] then do (i) -> after i*1000, -> console.log i
Finally, I think your gripes about object literal syntax are FUD. Nothing is forcing you to omit braces in object literals, it is merely a convenience. Further, idiomatic coffeescript would have you write the following to make it clear that the items are part of the same object.
someFunction 500,
abc : 123
def : 456
If you actually need them to be different objects, you write it like this.
someFunction 500,
abc: 123
def: 456
,
abc: 789
def: 012
This syntactic form is especially useful for jquery people
$.ajax "http://maps.googleapis.com/maps/api/geocode/output",
method: "GET"
params:
address: "1600 Amphitheatre Parkway, Mountain View, CA"
sensor: false
success: (data) ->
alert data.results.geometry.location
error: (_, textStatus, errorThrown) ->
alert "#{textStatus}: #{errorThrown}"
$("div.special").css
backgroundColor: "pink"
color: "darkred"
border: "1px dashed purple"
The point is that EVERY language has multiple ways of writing the same thing. The trick is to make sure that you follow the established language idioms (or establish your own styleguide, and stick to it).
All of the optional brackets in coffeescript are just that. Optional. If you find that a piece of code is ambiguous, add some brackets and remove the ambiguity.