Difference between these two namespaces in javascript

Posted by Lol coder on Stack Overflow See other posts from Stack Overflow or by Lol coder
Published on 2011-06-26T22:59:07Z Indexed on 2011/06/27 0:22 UTC
Read the original article Hit count: 274

Filed under:

First off, all I'm trying to do is to structure my javascript code properly. I've been told I must not have anything global. So I took the 2 types of namespaces declaration from this answer and now asking you guys for the pros and cons of each.

    var namespace1 = new function () {
        var internalFunction = function () {
        };

        this.publicFunction = function () {
        };
    };

    var namespace2 = {
        publicFunction: function () {
        }
    };

Also, how do i have a private function in the last one namespace2?

© Stack Overflow or respective owner

Related posts about JavaScript