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
Post a Comment