【发布时间】:2013-04-17 23:09:32
【问题描述】:
试图找出完成这项工作的最佳方法:
class Person
constructor: (@el) ->
@el = $(el)
this.bind()
bind: ->
@el.find('.something').on 'click', ->
$(this).hide() # conflict!
this.do_something() # conflict!
do_something: ->
alert 'done!'
我知道我可以使用 散列火箭 (=>) 然后从我的回调中访问 this.do_something,但是这与 callback 'this' 冲突,所以 jquery 试图选择对象,而不是 element '.something'。如何解决?
【问题讨论】:
标签: javascript jquery coffeescript