在咖啡脚本中有以下课程:
class Canvas
constructor: (finder) ->
@canvas = $(finder)
@mouse_down()
mouse_down: ->
@canvas.mousedown (e) ->
mouse_x = e.pageX - @offsetLeft
### ... ###
@redraw()
redraw: ->
### ... ###
问题是在函数中调用类对象redraw
方法。mousedown
最好的解决方案是什么?我只发现:
mouse_down: ->
@canvas.mousedown (e) =>
mouse_x = e.pageX - @canvas[0].offsetLeft
### ... ###
@redraw()