我有一些coffeescript,如下所示:
class foo:
@bar = 'bob loblaw'
processRows: ->
$("#my-table>tr").each ->
id = $(this).attr("id")
@processRow id
processRow: (id) ->
console.log @bar + id
所以我的问题是:我需要this
在循环内引用.each
上下文以获取id
,但我也希望this
在foo.processRow()
内引用类实例-这是它目前没有做的。
在.each
函数外部使用像_this = this
这样的东西并传递它也不是一个很好的解决方案,因为我在processRow
中引用了许多类变量。
有什么想法吗?我是不是漏掉了什么明显的东西?谢谢!
https://stackoverflow.com/questions/7261480
复制相似问题