mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
a passing test for destructuring assignment (it needs a better name)
This commit is contained in:
46
test/fixtures/execution/test_destructuring_assignment.coffee
vendored
Normal file
46
test/fixtures/execution/test_destructuring_assignment.coffee
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
a: -1
|
||||||
|
b: -2
|
||||||
|
|
||||||
|
[a, b]: [b, a]
|
||||||
|
|
||||||
|
print(a is -2)
|
||||||
|
print(b is -1)
|
||||||
|
|
||||||
|
|
||||||
|
arr: [1, 2, 3]
|
||||||
|
|
||||||
|
[a, b, c]: arr
|
||||||
|
|
||||||
|
print(a is 1)
|
||||||
|
print(b is 2)
|
||||||
|
print(c is 3)
|
||||||
|
|
||||||
|
|
||||||
|
obj: {x: 10, y: 20, z: 30}
|
||||||
|
|
||||||
|
{x: a, y: b, z: c}: obj
|
||||||
|
|
||||||
|
print(a is 10)
|
||||||
|
print(b is 20)
|
||||||
|
print(c is 30)
|
||||||
|
|
||||||
|
|
||||||
|
person: {
|
||||||
|
name: "Bob"
|
||||||
|
family: {
|
||||||
|
brother: {
|
||||||
|
addresses: [
|
||||||
|
"first"
|
||||||
|
{
|
||||||
|
street: "101 Deercreek Ln."
|
||||||
|
city: "Moquasset NY, 10021"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{name: a, family: {brother: {addresses: [one, {city: b}]}}}: person
|
||||||
|
|
||||||
|
print(a is "Bob")
|
||||||
|
print(b is "Moquasset NY, 10021")
|
||||||
Reference in New Issue
Block a user