javascript - Object litterals vs Module pattern -


i understand difference between 2 following patterns. in fact, second 1 allows mimic public , private method, there other difference ?

var mymodule = {    myproperty: "somevalue",   ...   mymethod: function () {     console.log( "anything" );   }  }; mymodule.mymethod(); 

and :

    var mymodule = (function(){        var myproperty= "somevalue";        ...        return {            mymethod: function(){                console.log('something');            }        }      })(); mymodule.mymethod(); 

the second 1 first, except provides closure around object "private" variables can kept.

specifically, if set example second such had no local variables , no parameters anonymous function, it'd not having anonymous function @ all.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -