// WAY 1: we can create the structure with local references (function () { // If you use local/cached references is recommended declare them // within a function or module at the top of your function scope; // this is called: Dependency declaration pattern var _2d = createNS("animation.g2D"), _3d = createNS("animation.g3D"); // you can get the reference of created namespaces _2d.slide = function() {}; _3d.cubic = function() {}; }()); // WAY 2: passing the object reference as a proxy (function (proxy2D) { proxy2D.slide = function() {}; })(createNS("animation.g2D")); (function (proxy3D) { proxy3D.cubic = function() {}; })(createNS("animation.g3D")); // WAY 3...n, you can use Module Pattern: loose augmentation, etc...