1 # These examples are taken from
2 # http://jashkenas.github.com/coffee-script/
4 song = ["do", "re", "mi", "fa", "so"]
18 eldest = if 24 > 21 then "Liz" else "Ike"
20 six = (one = 1) + (two = 2) + (three = 3)
22 My.mood = greatly_improved if true
29 Account = (customer, cart) ->
33 $('.shopping_cart').bind 'click', (event) =>
34 @customer.purchase @cart
38 alert @name + " moved " + meters + "m."
41 @name.replace(/^[\w_-]*$/g, "-")
43 class Snake extends Animal
44 constructor: (name) ->
51 class Horse extends Animal
52 constructor: (name) ->
59 sam = new Snake "Sammy the Python"
60 tom = new Horse "Tommy the Palomino"
64 if car.speed < speed_limit then accelerate()
66 print "My name is " + @name
68 gold = silver = the_field = "unknown"
70 award_medals = (first, second, rest...) ->
80 award_medals contenders...
83 alert "Silver: " + silver
84 alert "The Field: " + the_field
89 lunch = eat food for food in ['toast', 'cheese', 'wine']
101 # Naive collision detection.
102 for roid in asteroids
103 for roid2 in asteroids when roid isnt roid2
104 roid.explode() if roid.overlaps roid2
106 years_old = max: 10, ida: 9, tim: 11
108 ages = for child, age of years_old
112 if student.excellent_work
114 else if student.okay_stuff
115 if student.tried_hard then "B" else "B-"