Guest User

Untitled

a guest
Sep 22nd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Blah
  2.     constructor:()->
  3.         @test = "Hello!"
  4.  
  5.     bindy:()->
  6.         $(window).bind 'some_event',@_myHandler
  7.  
  8.     _myHandler:()->
  9.         // "this" is NOT the scope you would expect. "this" refers to the event object
  10.         // this will complain that test is undefined
  11.         alert @test
  12.  
  13. class Blah2
  14.     bindy:()->
  15.         ths = this
  16.         @_myHandler = ()->
  17.             // this will work correctly
  18.             alert ths.test
  19.    
  20.         $(window).bind 'some_event',@_myHandler
Add Comment
Please, Sign In to add comment