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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -