【发布时间】:2013-02-02 10:06:55
【问题描述】:
您好,我是 Js 和 Coffeescript 的新手,在下面的示例中,我觉得很难引用父对象的属性 App
App =
init: ->
this.foo = 'bar'
this.bindEvent()
bindEvent: ->
$('#test').click(this.show)
show: ->
alert this.foo
App.init()
我认为胖箭头可以解决问题,但是一旦我更改为show: =>,this 在show 方法的上下文中指的是窗口对象,而不是我想要的App 对象
.谁能告诉我怎么做对吗?
【问题讨论】:
-
查看这个答案以讨论胖箭头。 stackoverflow.com/questions/13184209/…转se
标签: coffeescript arrow-functions