我在使用 Coffeescript 时正在处理一些范围问题。
drawFirstLine: (currentAngle) ->
currentAngle = currentAngle # = 1
switch @type
# set @endAngle to pick up later on
# Math.PI * 2 is the endpoint of a circle divided by seconds times current seconds
when "seconds" then @endAngle = Math.PI * 2 / 60 * @seconds
when "minutes" then @endAngle = Math.PI * 2 / 60 * @minutes
when "hours" then @endAngle = Math.PI * 2 / 24 * @hours
@context.arc(@center_x, @center_y, 100, @startAngle, currentAngle, @counterClockWise)
@context.lineWidth = 15
console.log('drawn')
text = "28px sans-serif";
@context.fillText(text, @center_x - 28, @center_y - @canvas.width / 5)
@context.stroke()
currentAngle++;
if currentAngle < @endAngle
requestAnimationFrame( -> @drawFirstLine(currentAngle / 100) )
正如您在上面代码的底部看到的那样,我试图一次又一次地调用我们所在的函数。但问题是我不能@drawFirstLine
在另一个函数(requestAnimationFrame 函数)中使用。在普通的 javascript 中,我可以使用var self = this
和引用 self. 但是有谁知道如何在咖啡脚本中处理这个问题?
提前致谢,