I'm about to start building a small javascript module for an app. I've been exposed to two different ways of organizing code: the object literal and the IIFE. I know that with the IIFE, all variables and functions remain private unless otherwise made public, but are there any other reasons why I would use that over the object literal?
Why would I use the object literal:
var gojiraSays = 'Toxic Garbage Island!!!'
var app = {
printStuff: function(){
console.log(gojiraSays)
}
}
...over say the IIFE version:
var app = (function(){
var gojiraSays = 'Toxic Garbage Island!!!'
var yellGojira = function(){
console.log(gojiraSays);
}
return{
yellGojira: yellGojira
}
}());
app.yellGojira();