Created
August 28, 2015 12:07
-
-
Save chuck0523/fe073f592305d7db37a2 to your computer and use it in GitHub Desktop.
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, 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