Coffeescript fat arrow access not parental 'this'

That works great

@nav.on 'click', -> _this.mover _this.nav.index $(@) 

but I wonder if I can use the bold arrow instead, namely

  @nav.on 'click', => @mover @nav.index $(????) 

but what would I put in place of @ , which would result in this instead of _this ?

+7
source share
1 answer

JQuery event handlers receive an event object as an argument and that the event object has target and currentTarget properties:

 @nav.on 'click', (ev) => @mover @nav.index $(ev.currentTarget) 

You may need one of the other ev properties , depending on your specific circumstances.

+15
source

All Articles