JavaScript Module assignment pattern -


i reading a javascript module pattern, , wondering why bother module assignment firing immediate anonymous function call this:

yahoo.myproject.mymodule = function () {      return  {         mypublicproperty: "i'm accessible yahoo.myproject.mymodule.mypublicproperty.",         mypublicmethod: function () {             yahoo.log("i'm accessible yahoo.myproject.mymodule.mypublicmethod.");         }     };  }(); 

instead of directly assign object yahoo.myproject.mymodule this:

yahoo.myproject.mymodule = {         mypublicproperty: "i'm accessible yahoo.myproject.mymodule.mypublicproperty.",         mypublicmethod: function () {             yahoo.log("i'm accessible yahoo.myproject.mymodule.mypublicmethod.");         }     }; 

in example, there isn't point. didn't read enough of document linked to.

section 3 add "private" methods , variables in anonymous function prior return statement., , demonstrates why want use ieff here.

it can define local variables accessible functions making public, aren't directly accessible themselves.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -