When I started the creating new namespace JS library I got very useful artile to read.
http://pietschsoft.com/post/2007/07/Creating-Namespaces-in-JavaScript-is-actually-rather-simple.aspx
In this article they covered lot of things ( namespace protection objective )
Here I am using the namespace manager code:
04 | if ( typeof Namespace == 'undefined' ) var Namespace = {}; |
05 | if (!Namespace.Manager) Namespace.Manager = {}; |
08 | Register: function (namespace){ |
09 | namespace = namespace.split( '.' ); |
11 | if (!window[namespace[0]]) window[namespace[0]] = {}; |
13 | var strFullNamespace = namespace[0]; |
14 | for ( var i = 1; i < namespace.length; i++) |
16 | strFullNamespace += "." + namespace[i]; |
17 | eval( "if(!window." + strFullNamespace + ")window." + strFullNamespace + "={};" ); |
24 | Namespace.Manager.Register( "Dummy.Utility.Class" ); |
26 | Here I regestered the namspace. |
28 | Dummy.Utility.Class.dunnyClass = function () { |
30 | this .test= function (){alert( "test" );} |
32 | this .test2= function (){alert( "test2" );} |
Using this namaspace JS class in HTML.
1 | var dumdum = new Dummy.Utility.Class.dunnyClass(); |