Daniel, you said, "If it's basically a style choice . " I know at least two examples in javascript when the “code style” is not only a matter of preference, but also a different result.
Are semicolons optional? It's my pleasure.
$scope.test = function() { console.log('Weird behaviour!') }
equally
$scope.test = function() { console.log('Weird behaviour!') }(function() {} ());
Another example of a "code style" that is not related to self-starting functions:
var x = (function() { return
Code style formation is dictated by unexpected results of this kind.
Last but not least. With a self-closing function: a closure is created when the function is called and keeps your variables local.
A closure is created when a function is called. That is why the self-reproducing function is so convenient. As Daniel correctly noted, this is a good place to store an independent code unit, this template is called a modular template . Therefore, when you switch from pure javascript to a specific environment or vice versa, this independence makes code changes smoother. The best option is to simply move your module to the corner wrapper and reuse it.
So it’s convenient for transferring code from one technology to another. But, I believe, this does not make sense for a specific framework.
source share