JavaScript Namespace Declaration

Posted by Hery on Stack Overflow See other posts from Stack Overflow or by Hery
Published on 2010-03-24T00:15:09Z Indexed on 2010/03/24 0:23 UTC
Read the original article Hit count: 247

Filed under:

I created a javascript class as follow:

var MyClass = (function() {
   function myprivate(param) {
      console.log(param);
   }

   return {
      MyPublic : function(param) {
         myprivate(param);
      }
   };
})();

MyClass.MyPublic("hello");

The code above is working, but my question is, how if I want to introduce namespace to that class.

Basically I want to be able to call the class like this:

Namespace.MyClass.MyPublic("Hello World");

If I added Namespace.MyClass, it'll throw error "Syntax Error". I did try to add "window.Namespace = {}" and it doesn't work either.

Thanks.. :)

© Stack Overflow or respective owner

Related posts about JavaScript