Skip to content

Instantly share code, notes, and snippets.

@PetrKaleta
Created January 3, 2012 21:38
Show Gist options
  • Save PetrKaleta/1557073 to your computer and use it in GitHub Desktop.
Save PetrKaleta/1557073 to your computer and use it in GitHub Desktop.
How to work properly with event listeners in CoffeeScript classes
class SomeClass
constructor: ->
@message = 'Page scrolled'
window.addEventListener 'scroll', @onPageScrolled, no
# note I'm using a fat arrow (check how the compiler handle it)
onPageScrolled: =>
alert @message
shutUp: ->
window.removeEventListener 'scroll', @onPageScrolled, no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment