jashkenas--coffeescript/test/test_assignment.coffee

29 lines
445 B
CoffeeScript
Raw Normal View History

# Can assign the result of a try/catch block.
2010-07-25 05:23:37 +00:00
result = try
2010-01-17 15:40:59 +00:00
nonexistent * missing
catch error
true
2010-07-25 05:23:37 +00:00
result2 = try nonexistent * missing catch error then true
2010-01-17 15:40:59 +00:00
ok result is true and result2 is true
2010-01-17 15:40:59 +00:00
# Can assign a conditional statement.
2010-07-25 05:23:37 +00:00
getX = -> 10
2010-01-17 15:40:59 +00:00
2010-07-25 05:23:37 +00:00
if x = getX() then 100
2010-01-17 15:40:59 +00:00
ok x is 10
2010-01-17 15:40:59 +00:00
2010-07-25 05:23:37 +00:00
x = if getX() then 100
2010-01-17 15:40:59 +00:00
ok x is 100
# This-assignment.
2010-07-25 05:23:37 +00:00
tester = ->
@example = -> 'example function'
this
ok tester().example() is 'example function'