Instantly share code, notes, and snippets.

Embed
What would you like to do?
# function
###
JSではこう書く
function hello() {}
var hello = function() {}
coffeeでは後者!
###
# 基本形
hello = ->
console.log "hello"
hello = -> console.log "hello"
hello()
# 引数あり
helloName = (name) -> console.log "hello #{name}"
helloName "chuck" # hello chuck
# デフォルト引数も設定可
helloDefault = (name = "defo") -> console.log "hello #{name}"
helloDefault() # hello defo
# 戻り値
helloReturn = -> "hello"
msg = helloReturn()
console.log msg # hello
# 即時関数
###
JSではこう書く
(function(){
hoge
})
###
do -> console.log "hello" # hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment