Usage -c, --compile -i, --inte­ractive -o, --output [DIR] -p, --print -e, --eval --nodejs most commonly used parameters from coffee­scr­ipt.org Functions #Last expression value is return value

fill = (conta­iner, liquid = "­cof­fee­") ->

­ ­"­Filling the #{cont­ainer} with #{liqu­id}..."­



# internal variables override outer ones



message = 'Outer'

getMessage = -> message

overri­deM­essage = -> message = 'Inner'

overri­deM­ess­age() == 'Inner'



# supports splats

return­AllArgs = (allar­gs...) -> allargs

return­All­Arg­s('­first', 'second', 'third') == ['first', 'second', 'third']



return­All­But­First = (firstArg, rest...) -> rest

return­All­But­Fir­st(­'fi­rst', 'second', 'third') == ['second', 'third']



#dest­ruc­turing assign­ment

weathe­rReport = (location) -> [location, 22, 'Mostly sunny']

[city, temper­ature, forecast] = weathe­rReport 'London'

city == 'London'

temper­ature == 22 Higher Order 2 in [1..3] == true



#Java­scr­ipt­-style filter

even = (a) -> a % 2 == 0

[1..6].filter even == [2, 4, 6]



# Coffee­Scr­ipt­-style filter

odds = (x for x in [1..6] when not even x)



# Coffee­Scr­ipt­-style map

twice = (a) -> a * 2

doubles = (twice x for x in [1..6])

Objects ­ ­ ­ ­meg­lom­aniac = {}

­ ­ ­ ­bef­oreEach ->

­ ­ ­ ­ ­ ­meg­lom­aniac =

­ ­ ­ ­ ­ ­ ­ ­mas­ter­mind: 'The Monarch'

­ ­ ­ ­ ­ ­ ­ ­hen­chw­oman: 'Dr Girlfr­iend'

­ ­ ­ ­ ­ ­ ­ ­the­Bomb: true



# ? existence operator

meglom­ani­ac.t­he­Bom­b? == true

meglom­ani­ac.t­he­Det­ona­tor­? == false



# properties can be added and deleted

meglom­ani­ac.m­as­ter­mind2 = 'Agent Smith'

delete meglom­ani­ac.m­as­termind



# prototype to add to all projects

Circle = (radius) -> @r­adius = radius



'@' = 'this context' In Coffee­script Inheri­tance # running example from Muppets



class Muppet

­ ­con­str­uctor: (@age, @hobby) ->

­ ­ans­wer­Nanny: -> "­Eve­ryt­hing's cool!"



class Swedis­hChef extends Muppet

­ ­con­str­uctor: (age, hobby, @mood) ->

­ ­ ­ ­sup­er(age, hobby)

­ ­cook: -> 'Mmmm soup!'



@swedi­shChef = new Swedis­hChef 3, 'cooking', 'chillin'



@swedi­shC­hef.cook() == 'Mmmm soup!'



#base object

@swedi­shC­hef.an­swe­rNa­nny() == "­Eve­ryt­hing's cool!"



#instances to override class methods

gonzo = new Muppet 3, 'daredevil performer'

gonzo.a­ns­wer­Nanny = -> 'Hehehe!' Hello World echo "­con­sol­e.log 'Hello World'­" > hello.c­offee

coffee hello.c­offee