[ ] Pattern-matching ( ) coffeescript
|
|
, 23 2015 . 12:32
+
- . - , -, . JavaScript, , , map/filter/fold, , , . 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
, .
→ http://habrahabr.ru/post/253761/
:
javascript
coffeescript
pattern matching