Skip to content

Instantly share code, notes, and snippets.

@nilsnh nilsnh/gist:5097730
Last active Dec 14, 2015

What would you like to do?
Just a simple Harry Potter inspired coffee-script to wow and excite. :)
#A function
cast = (spell) ->
console.log "Casting spell: #{spell}"
#Comprehensions. "Syntactic sugar"
mySpellList = ['Expelliarmus', 'Lumos', 'Tarantallegra']
cast spell for spell in mySpellList
#Same as
for spell in mySpellList
cast spell
#If checks as oneliners
spellCast = () -> 'Nox'
if spellCast() is 'Nox' then cast 'Lumos'
#A more expressive 'if not'
invisible = true
unless invisible is true then console.log 'Mrs. Norris will spot us.'
#Checking for null and undefined
if safe? then console.log 'Open the door' else console.log "Don't open it!"
#Functional fanciness
spellComb = (spell, callback) ->
cast = (spell) -> "#{spell}"
nextSpell = () -> if callback? then "-#{callback}" else ''
console.log spellComb('Protego', spellComb('Incendio', spellComb('Tarantallegra')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.