正确的方法返回函数值而不是Coffeescript中的绑定

时间:2012-12-13 18:47:15

标签: coffeescript

我似乎无法找到这个问题的简明答案。在调用@_instanceMethod而不是函数绑定本身时,从_otherInstanceMethod返回值的正确coffeescriptic方法是什么?

x = _instanceMethod: () ->
    @_otherInstanceMethod key: 'value'

编辑(感谢评论者)

返回:

x = function () {
    [...] # function body omitted    
});

而不是

x = 'some value returned by _otherInstanceMethod'

我希望返回值,而不是函数绑定到_otherInstanceMethod

2 个答案:

答案 0 :(得分:0)

对Coffeescript来说是全新的,这是我的错。我正在调用实例方法,如:

@_instanceMethod

而不是

@_instanceMethod()

对不起,请注意删除

答案 1 :(得分:-1)

在CoffeeScript中@something转换为this.something,无论底层变量类型如何。这意味着您只能将@与属性结合使用,方法仍然应该使用旧的this

相关问题