Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 分割代入
[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