Just out of pure curiosity I have seen codes like below
let GlobalActions = function () {
let doSomething= function () {
//Do Something
};
return {
doSomething: function () {
doSomething()
}
};
}();
GlobalActions.doSomething();
At first, I thought it was about scoping, maybe var
declared variables from outside is not accessible from each functions inside after it has been initialized; however, that was not true.
Then it came to me thinking what is the advantage of doing the above instead of the below?
let GlobalActions = {
doSomething: function () {
//Do Something
};
};
GlobalActions.doSomething();