mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
moving right along
This commit is contained in:
87
code.jaa
87
code.jaa
@@ -1,47 +1,54 @@
|
||||
# I'm a comment and I'm ok.
|
||||
# Return
|
||||
# Case
|
||||
# TODO: switch/case statements
|
||||
# new Function()
|
||||
# Regexes
|
||||
|
||||
# Functions:
|
||||
# square: x => x * x.
|
||||
#
|
||||
# sum: x, y => x + y.
|
||||
#
|
||||
# odd: x => x % 2 is 0.
|
||||
#
|
||||
# even: x => x % 2 aint 0.
|
||||
#
|
||||
# run_loop: =>
|
||||
# fire_events(e => e.stopPropagation().)
|
||||
# listen()
|
||||
# wait().
|
||||
#
|
||||
# # Objects:
|
||||
# object_literal: {one: 1, two: 2, three: 3}
|
||||
#
|
||||
# multiline_object: {
|
||||
# pi: 3.14159
|
||||
# list: [1, 2, 3, 4]
|
||||
# three: 3
|
||||
# inner_obj: {
|
||||
# freedom: => _.freedom().
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# # Arrays:
|
||||
# stooges : [{moe: 45}, {curly: 43}, {larry: 46}]
|
||||
square: x => x * x.
|
||||
|
||||
arithmetic : [one, two, three, four]
|
||||
|
||||
#
|
||||
# if submarine.shields_up
|
||||
# full_speed_ahead()
|
||||
# weapons.fire_torpedos()
|
||||
# else
|
||||
# run_away().
|
||||
#
|
||||
# eldest: if 25 > 21 then liz else marge.
|
||||
sum: x, y => x + y.
|
||||
|
||||
odd: x => x % 2 is 0.
|
||||
|
||||
even: x => x % 2 aint 0.
|
||||
|
||||
run_loop: =>
|
||||
fire_events(e => e.stopPropagation().)
|
||||
listen()
|
||||
wait().
|
||||
|
||||
# Objects:
|
||||
object_literal: {one: 1, two: 2, three: 3}
|
||||
|
||||
multiline_object: {
|
||||
pi: 3.14159
|
||||
list: [1, 2, 3, 4]
|
||||
three: 3
|
||||
inner_obj: {
|
||||
freedom: => _.freedom().
|
||||
}
|
||||
}
|
||||
|
||||
# Arrays:
|
||||
stooges : [{moe: 45}, {curly: 43}, {larry: 46}]
|
||||
|
||||
exponents : [x => x., x => x * x., x => x * x * x.]
|
||||
|
||||
# Conditionals and ternaries.
|
||||
if submarine.shields_up
|
||||
full_speed_ahead()
|
||||
weapons.fire_torpedos()
|
||||
else
|
||||
run_away().
|
||||
|
||||
eldest: if 25 > 21 then liz else marge.
|
||||
|
||||
# Returning early:
|
||||
race: =>
|
||||
run()
|
||||
walk()
|
||||
crawl()
|
||||
if tired then return sleep().
|
||||
race().
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user