Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 28, 2015 12:07
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/fe073f592305d7db37a2 to your computer and use it in GitHub Desktop.
Save chuck0523/fe073f592305d7db37a2 to your computer and use it in GitHub Desktop.
# 分割代入
[a, b, c] = [1, 5, 10]
console.log a for a in [a, b, c]
# 1 5 10
# 入れ替え
x = 10
y = 20
show = (a, b) -> console.log "#{a} : #{b}"
show(x, y) # 10 : 20
[x, y] = [y, x]
show(x, y) # 20 : 10
# 複数の値を返す関数
results = (x) -> [x, x ** 2, x ** 3]
[a, b, c] = results 5
console.log a for a in [a, b, c]
# 5 25 125
# オブジェクトから複数の値を取り出す
user =
name : "chuck"
score : 60
email : "chuck@mail"
{name, email} = user
console.log name # chuck
console.log email # email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment