I came across this code, which I don't understand what is going on, and then I removed the IIFE parenthesis and the console.log didn't work anymore, can someone explain what is going on, It is called the classic module pattern. Why we want to use it?
var foo = (function(){
var publicAPI = {
bar: function(){
publicAPI.baz()
},
baz: function(){
console.log('baz')
}
}
return publicAPI
})()
foo.baz()
foo.bar()
removing the IIFE parenthesis the console.log doesn't work anymore.
var foo = function(){
var publicAPI = {
bar: function(){
publicAPI.baz()
},
baz: function(){
console.log('baz')
}
}
return publicAPI
})
Thank you a lot in advance.