So far I'm hearing that the "module" (or "closure") pattern can have
slow performance, so don't use it as a default.
So if it's between the literal (or 'singleton' as I understand
Crockford to call it) pattern and the namespace pattern, then which
one should we use?
The only meaningful difference I can see left is that the singleton
pattern does not allow one method to use the other methods. So the
following won't work...
namespace = {
a: function() {
return "hello world";
},
b: function() {
alert( a() );
}
}
because `a` hasn't been defined, but the following will work...
namespace = {};
namespace.a = function() {
return "hello world";
};
namespace.b = function() {
alert( namespace.a() );
};
So my conclusion is to use the namespace pattern because:
1) closure pattern can have slow performance
2) singletons don't allow mutual usage or recursion.
--
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]