[ ] Pattern-matching ( ) coffeescript |
fn = Match -> [
When {command: draw, figure: @figure = {type: circle, radius: @radius}}, ->
console.log(@figure, @radius)
When {command: draw, figure: @figure = {type: polygon, points: [@first, @second | @rest]}}, ->
console.log(@figure, @first, @second, @rest);
]
fn {command: draw, figure: {type: circle, radius: 5, color: red}}
#output: {type: circle, radius: 5, color: red} 5