(function() { dosth; })();
Syntax
declares an anonymous function and then executes it immediately. This is equivalent to this:
var myFun = (function() { dosth; }); myFun();
but without a temporary variable.
In a broad sense, this is like doing all of dosth ; but creating a function object introduces a new scope for variables (due to closure), and thus it is often used to solve problems using scope.
In the specific case that you quoted, I see no reason why this would be especially necessary. However, this can be done for two reasons: either the last Javascript itself is generated by some automatic process that cannot determine if closing is required; or it was written by a person who decided to always wrap things in functions to be safe.
source share