Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coffeescript fat arrow access not parent 'this'

This works great

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

but I am wondering if I can use a fat arrow instead like this

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

but what would I put in place of @ that will result in this instead of _this?

like image 461
Fresheyeball Avatar asked Apr 20 '12 21:04

Fresheyeball


1 Answers

jQuery event handlers get an event object as an argument and that event object has target and currentTarget properties:

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

You might want one of the other properties of ev depending on your specific circumstances.

like image 144
mu is too short Avatar answered Nov 15 '22 00:11

mu is too short