Got the DRY object pattern matching style working properly, from Harmony. {name, age}: person now works correctly.

This commit is contained in:
Jeremy Ashkenas
2010-04-25 22:21:53 -04:00
parent 328a14014c
commit a894db35fd
6 changed files with 223 additions and 183 deletions

View File

@@ -89,8 +89,24 @@ test: {
ok addr.join(', ') is "Street 101, Apt 101, City 101"
# Destructuring against an expression.
# Pattern matching against an expression.
[a, b]: if true then [2, 1] else [1, 2]
ok a is 2
ok b is 1
# Pattern matching with object shorthand.
person: {
name: "Bob"
age: 26
dogs: ["Prince", "Bowie"]
}
{name, age, dogs: [first, second]}: person
ok name is "Bob"
ok age is 26
ok first is "Prince"
ok second is "Bowie"