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