jashkenas--coffeescript/test/test_blocks.coffee

35 lines
418 B
CoffeeScript
Raw Normal View History

# Basic blocks.
2010-07-25 05:23:37 +00:00
results = [1, 2, 3].map (x) ->
x * x
ok results.join(' ') is '1 4 9'
# Chained blocks, with proper indentation levels:
2010-07-25 05:23:37 +00:00
results = []
2010-07-25 05:23:37 +00:00
counter = {
tick: (func) ->
results.push func()
this
}
counter
.tick ->
3
.tick ->
2
.tick ->
1
ok results.join(' ') is '3 2 1'
# Make incorrect indentation safe.
2010-07-25 05:23:37 +00:00
func = ->
obj = {
key: 10
}
obj.key - 5
ok func() is 5