coffeescript fat arrow访问不是父母'这个'

Fre*_*all 7 jquery coffeescript arrow-functions

这非常有效

    @nav.on 'click', ->
        _this.mover _this.nav.index $(@)
Run Code Online (Sandbox Code Playgroud)

但我想知道我是否可以使用胖箭而不是这样

    @nav.on 'click', =>
        @mover @nav.index $(????)
Run Code Online (Sandbox Code Playgroud)

但我会落实到位@,这将导致this代替_this

mu *_*ort 15

jQuery的事件处理程序获得的事件对象作为参数,该事件对象有targetcurrentTarget属性:

@nav.on 'click', (ev) =>
    @mover @nav.index $(ev.currentTarget)
Run Code Online (Sandbox Code Playgroud)

根据您的具体情况,您可能需要其他属性之一ev.

  • 如果`@ nav`条目具有嵌套元素,则应该使用`ev.currentTarget` - 在集合中找不到后代. (3认同)