On Feb 24, 9:18 am, Asen Bozhilov <[email protected]> wrote:
[...]
> You can use the follow design:
>
> var widget = (function () {
> var user; //Assign a value of user
>
> function initViewPort() {
> //...
> }
>
> function initHeaderPanel() {
> //...
> }
>
> function initMenuPanel() {
> //...
> }
>
> function initQuotesPanel() {
> //...
> }
>
> return {
> initViewPort : initViewPort,
> initHeaderPanel : initHeaderPanel,
> initMenuPanel : initMenuPanel,
> initQuotesPanel : initQuotesPanel
> }
>
> })();
I guess you like this pattern (I'll call it the "declarative module
pattern") because it uses function declarations over statements, but I
find the more traditional pattern makes it easier to see what is
private and what is public:
var widget = (function() {
// Private stuff
//...
return {
// Public/priveliged stuff
initViewPort: function() {
//...
},
//...
}
})();
The delcarative pattern allows public functions to call each other
without needing to know how they themselves were called (e.g. they can
just call initViewPort rather than widget.initViewPort or
this.initViewPort or whatever), so that might be an advantage.
There is also the "additive module pattern", again each function has a
closure to all the others so methods calling each other is easy:
var widget = {};
(function() {
function initViewPort() {
//...
}
widget.initViewPort = initViewPort;
function initHeaderPanel() {
//...
}
widget.initHeaderPanel = initViewPort;
})();
--
Rob
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]