2010-04-03 14:39:32 +00:00
|
|
|
# Basic blocks.
|
2010-07-25 05:23:37 +00:00
|
|
|
results = [1, 2, 3].map (x) ->
|
2010-01-03 15:46:37 +00:00
|
|
|
x * x
|
|
|
|
|
2010-04-03 14:39:32 +00:00
|
|
|
ok results.join(' ') is '1 4 9'
|
2010-02-28 17:49:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Chained blocks, with proper indentation levels:
|
2010-07-25 05:23:37 +00:00
|
|
|
results = []
|
2010-02-28 17:49:37 +00:00
|
|
|
|
2010-07-25 05:23:37 +00:00
|
|
|
counter = {
|
2010-02-28 17:49:37 +00:00
|
|
|
tick: (func) ->
|
|
|
|
results.push func()
|
|
|
|
this
|
|
|
|
}
|
|
|
|
|
|
|
|
counter
|
|
|
|
.tick ->
|
|
|
|
3
|
|
|
|
.tick ->
|
|
|
|
2
|
|
|
|
.tick ->
|
|
|
|
1
|
|
|
|
|
2010-06-02 03:32:46 +00:00
|
|
|
ok results.join(' ') is '3 2 1'
|
|
|
|
|
|
|
|
|
|
|
|
# Make incorrect indentation safe.
|
2010-07-25 05:23:37 +00:00
|
|
|
func = ->
|
|
|
|
obj = {
|
2010-06-02 03:32:46 +00:00
|
|
|
key: 10
|
|
|
|
}
|
|
|
|
obj.key - 5
|
|
|
|
|
|
|
|
ok func() is 5
|