I have been working on an existing project that was coded by some developers that I do not know. Surfing on javascript files, I see that they use this specific notation for define function:
var ModuleScripts = (function() {
return {
init: function(){...}
};
}())
Note parenthesis enclosing function(){...}()
. This code works perfectly, but when I want to write something alike, I use this notation:
var ModuleScripts = function() {
return {
init: function(){...}
};
}()
My code works perfectly too. So my question is: Is there a good reason to use parenthesis surrounding function(){...}()
in JavaScript?