CoffeeScriptの関数定義には2種類ある
->
:通常の関数(JSのfunction)
this
が変わる=>
:this
を固定する関数(JSのアロー関数)
this
を維持し、呼び出し側のコンテキストに依存しないclass Counter
constructor: ->
@count = 0
@intervalId = setInterval (() => @count++), 1000
getCount: ->
@count
reset: ->
@count = 0
pause: ->
clearInterval @intervalId
→if文