这很好用
@nav.on 'click', ->
_this.mover _this.nav.index $(@)
但我想知道是否可以像这样使用粗箭头
@nav.on 'click', =>
@mover @nav.index $(????)
但是我应该用什么来代替 @
才能得到 this
而不是 _this
呢?
最佳答案
jQuery 事件处理程序获取一个事件对象作为参数,并且该事件对象具有 target
和 currentTarget
属性:
@nav.on 'click', (ev) =>
@mover @nav.index $(ev.currentTarget)
您可能想要 other properties of ev
之一根据您的具体情况。
关于jquery - CoffeeScript 粗箭头访问不是父级 'this',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253494/