jashkenas--coffeescript/documentation/coffee/overview.coffee

29 lines
414 B
CoffeeScript
Raw Normal View History

# Assignment:
2010-07-29 04:51:35 +00:00
number = 42
opposite = true
# Conditions:
2010-07-29 04:51:35 +00:00
number = -42 if opposite
# Functions:
2010-07-29 04:51:35 +00:00
square = (x) -> x * x
# Arrays:
2010-07-29 04:51:35 +00:00
list = [1, 2, 3, 4, 5]
# Objects:
2010-07-29 04:51:35 +00:00
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
2010-01-05 05:34:18 +00:00
# Splats:
2010-07-29 04:51:35 +00:00
race = (winner, runners...) ->
2010-01-25 05:14:00 +00:00
print winner, runners
2010-01-05 05:34:18 +00:00
# Existence:
2010-01-25 05:14:00 +00:00
alert "I knew it!" if elvis?
2010-01-05 05:34:18 +00:00
# Array comprehensions:
2010-11-21 17:38:27 +00:00
cubes = (math.cube num for num in list)