Created
January 3, 2012 21:38
-
-
Save PetrKaleta/1557073 to your computer and use it in GitHub Desktop.
How to work properly with event listeners in CoffeeScript classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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