您好我是新來的JS和的CoffeeScript指在事件處理程序的父對象,這裏的情況,我覺得很難參照這是App
在下面的示例中,父對象的屬性如何使用CoffeeScript的脂肪箭頭
App =
init: ->
this.foo = 'bar'
this.bindEvent()
bindEvent: ->
$('#test').click(this.show)
show: ->
alert this.foo
App.init()
我覺得胖箭頭可以做的伎倆,但一旦我在show
方法的上下文改爲show: =>
,this
指的不是我想要 App
對象window對象。任何人都可以告訴我該怎麼做對嗎?
看看這個答案的脂肪箭頭的討論。 http://stackoverflow.com/questions/13184209/when-does-the-fat-arrow-bind-to-this-instance/13184211#13184211 se – robkuz 2013-02-18 07:45:01