【发布时间】:2014-09-21 08:40:53
【问题描述】:
我似乎无法在属性上定义的函数内引用父对象。
SocketMixin = Ember.Mixin.create
thing: (->
'dougs'
).property()
getThing: ->
console.log @ # window object
@get('thing') # Uncaught TypeError: undefined is not a function
sameWithFatArrow: =>
console.log @ # window object
@get('thing') # Uncaught TypeError: undefined is not a function
printThing: ->
@get('getThing')() # call the above function
计算属性没有问题
thingProp: (->
@get('thing')
).property()
工作得很好。
我一直试图通过在参数中传递 @ 来解决这个问题,但我很确定肯定有比这更好的方法来调用这些函数。
getThing: (self) ->
console.log @ # window object
self.get('thing') # Uncaught TypeError: undefined is not a function
printThing: ->
@get('getThing')(@) # call the above function
真的,我只想调用一个方法。它应该比所有这些都更加困难!?!?
【问题讨论】:
标签: ember.js coffeescript scope this