Monday, October 5, 2009

How to do Namespaces in JavaScript

I just found a nice suggestion about how to do namespacing in JavaScript. In case it goes down or something, this is the gist:

var DED = function() {
    var private_var;
    function private_method() {
        // do stuff here
    }
    return {
        method_1 : function() {
            // do stuff here
        },
        method_2 : function() {
            // do stuff here
        }
    };
}();

No comments:

Post a Comment