Last active
December 14, 2015 13:59
-
-
Save nilsnh/5097730 to your computer and use it in GitHub Desktop.
Just a simple Harry Potter inspired coffee-script to wow and excite. :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 '' | |
"#{cast(spell)}#{nextSpell()}" | |
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