function _animationFunctions(){ //locally cached reference for speed var animationFunctions = this.animationFunctions = [], slice = [].slice; //we use this as a reference to a no Op function to give our API a way to remove animation functions later function noOp(){} //store these variable out of here so they never have to be allocated inside of your draw loop var _funcIndex = -1, _animationIndex = 0, _len = 0; requestAnimationFrame(function draw(){ _animationIndex = 0; _len = animationFunctions.length; for(;_animationIndex < _len;_animationIndex++) { animationFunctions[_animationIndex]();//call the function! } //find noOps that were declared inside of the draw loop _funcIndex = animationFunctions.indexOf(noOp); while(_funcIndex > -1){ //Always remove EVERY noOp function reference outside of the loop animationFunctions.splice(_funcIndex, 1); //get the next index _funcIndex = animationFunctions.indexOf(noOp); } }); this.removeAnimationFunctions = function(){ var idx = 0, funcIdx = -1, len = arguments.length; for(;idx<len;idx++){ funcIdx = animationFunctions.indexOf(arguments[idx]); if(funcIdx>0){ //this can be called INSIDE OF THE ANIMATION LOOP animationFunctions = noOp; //DO NOT SPLICE HERE } } }; } var Stage = SnowBlower({}, _animationFunctions);