I am using the famous module pattern for creating namespaces however its cumbersome to write ns1.ns2.member to access a member from ns3(ns1.ns2.ns3).
I do not like using a shortcut var(_ns2=ns1.ns2) for this purpose also with statement considered harmfull so what is the better to handle this problem?
is it possible to combine scope of namespaces or whatever? thanks.
var NS1 = (function ()
{
function $(id)
{
return document.getElementById(id);
}
return {
$: $
}
})();
NS1.NS2 = function()
{
function someFunc()
{
// Do not want the below one.
NS1.$('...');
// Is there a way to access $ directly.
// without defining a variable for it here or using with statement.
}
}();
I don’t really know what you’re talking about, and even if I make believe I do I don’t see what’s so bad about “ns1.ns2.ns3”, but here are a couple of ideas:
Or combine a few:
Some description of what it is you’re doing with these namespaces and how much code we’re talking about would be useful. I find that once you start using something like jQuery, for most pages — even with fairly complicated client-side behavior — the need for large long-term data structures goes way down.