Is there a way to cancel requestAnimationFrame without a global variable?
问题 I'm trying to cancel a requestAnimationFrame loop, but I can't do it because each time requestAnimationFrame is called, a new timer ID is returned, but I only have access to the return value of the first call to requestAnimationFrame . Specifically, my code is like this, which I don't think is entirely uncommon: function animate(elem) { var step = function (timestamp) { //Do some stuff here. if (progressedTime < totalTime) { return requestAnimationFrame(step); //This return value seems