Occasionally, I come across JavaScript constructs like this:
var foo = (function(){ return some_expression; })();
Why do developers use this pattern? How is it different from the simpler alternative:
var foo = some_expression;
I recently stumbled upon such an example here (the window.requestAnimFrame = ...
code) but I've seen it used in many other places as well.
I understand that one reason to wrap code in a lambda function is to maintain local scope for variables, however, that doesn't seem to be the case in this specific scenario.