Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 28, 2015 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/1c7478d2806591983c18 to your computer and use it in GitHub Desktop.
Save chuck0523/1c7478d2806591983c18 to your computer and use it in GitHub Desktop.
# 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