考虑以下代码脂肪箭头“这个”范围
_bindEvents: ->
@input.bind 'keyup', =>
@filter($(this).val())
if $this .val() is ''
@clearBtn.hide()
else
@clearBtn.show()
很清楚,我认为“@”代表“_this。”所以它引用了父范围,但是如果我需要'内心这个'。
喜欢这一行:
@filter($(this).val())
编译成这样:
_this.filter($(_this).val()); // $(_this)
,我需要这样的:
_this.filter($(this).val()); // $(this)
有没有办法做到这一点不使用细箭头并使用closue(that = this)手动保存该引用?
谢谢,这使得很多的感觉:) – escusado