accessing my public methods from within my namespace

Posted by Derek Adair on Stack Overflow See other posts from Stack Overflow or by Derek Adair
Published on 2011-01-05T19:33:26Z Indexed on 2011/01/05 19:54 UTC
Read the original article Hit count: 176

I am in the process of making my own namespace in JavaScript...

(function(window){
    (function(){
        var myNamespace = {
            somePublicMethod: function(){
            },
            anotherPublicMethod: function(){
            }
        }

        return (window.myNamespace = window.my = myNamespace)
    }());
})(window);

I'm new to these kinds of advanced JavaScript techniques and i'm trying to figure out the best way to call public methods from within my namespace. It appears that within my public methods this is being set to myNamespace.

Should I call public methods like...

AnotherPublicMethod: function(){
   this.somePublicMethod()
}

or...

AnotherPublicMethod: function(){
   my.somePublicMethod();
}

is there any difference?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about namespaces