Hi devs, I'd like to propose we adopt the module pattern for our XWiki's javascript modules.
The pattern and its variations is well described here : http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth I would follow the author advice and go for loose augmentation and sub-modules. I don't think we need private states. Main avantages I see over what we currently are doing are : * It enforces namespacing and the use of a private scope versus manual namespacing in the global window scope * It easily supports global imports (can be useful for example when using jQuery in addition to prototype) * It's more elegant and easier to read. For example : var XWiki = (function(XWiki, $j){ var mySubModule = XWiki.mySubModule = XWiki.mySubModule || {}; // my sub module code here return XWiki; })(XWiki, jQuery) instead of the tedious : if (typeof XWiki == "undefined") { XWiki = new Object(); } if (typeof XWiki.mySubModule == "undefined") { XWiki.mySubModule = new Object(); } // my sub module code here I'm +1 to adopt it. WDYT ? Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

