Ich habe mit einigen Umfang Probleme bei der Verwendung von Coffeescript.var self = das in 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))
Wie Sie am unteren Rand des obigen Code sehen kann ich die Funktion aufrufen, ich versuche, wo wir sind, wieder und wieder. Aber das Problem ist, dass ich @drawFirstLine
innerhalb einer anderen Funktion (die Funktion requestAnimationFrame) nicht verwenden kann. In einfachem Javascript kann ich var self = this
verwenden und auf self verweisen. Aber weiß jemand im Coffeescript, wie man damit umgeht?
Vielen Dank im Voraus,
möglich duplicate von [Problem, das Klassenobjekt in einer verschachtelten Funktion referenziert] (http://stackoverflow.com/questions/18281886/trouble-referencing-class-object-inside-a-nested-function) – Mathletics