there are a lot of places (e.g. How to use requestAnimationFrame?) that fix window.requestAnimationFrame as below. I do not understand why the right hand side of the assignment is wrapped in to a function call.
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
I’ve wondered the same thing before. I’m pretty sure Google just really likes closures. Granted there is not one variable in there, it’s a ‘safe’ thing to do.
As far as I can tell, this is the exact same thing, without any change of interfering with namespaces (a general reason to use a closure like that):