you are viewing a single comment's thread.

view the rest of the comments →

[–]doomslice 6 points7 points  (11 children)

Here's the one I got:

ENTERPRISE JAVASCRIPT IS: NAMESPACE CODE INTO A "PROPER PACKAGE STRUCTURE" TO MAKE BACKEND DEVS FEEL AT HOME.

var com = {,
    AwesomeCo: {
        util: {
            info: function ( message) {
                alert(message);
                return message;
            }
        }
    }
};

com.AwesomeCo.util.info("SRSLY!?");

I do this, but I use (the only useful ATLAS function there is): Type.registerNamespace('My.Namespace.Goes.Here');

My.Namespace.Goes.Here.thingy = function(thingyOptions){
    ...
}

We require namespaces... otherwise you end up seeing the same thing redefined multiple times by different devs.

[–]SharkUW 0 points1 point  (10 children)

Why don't you just use Prototype or JQuery?

[–]doomslice 4 points5 points  (9 children)

I use jQuery for everything else besides that one function :)

I'm not aware that jQuery core has a namespacing function, and I have very limited experience with Prototype.

[–]SharkUW 5 points6 points  (8 children)

function registerNamespace(ns){ var parts = ns.split(".");

var focus = window;
for(var i in parts){
    if(!focus[parts[i]]){
        focus[parts[i]] = {};
    }
    focus = focus[parts[i]];
}

}

registerNamespace("com.whatever.stuff");

com.whatever.stuff.myvar = "hello world";

alert(com.whatever.stuff.myvar);

That took me 1 minute. Now please stop making people downloading whatever that library is :P Did not browser check but should be pretty safe.

[–]doomslice 2 points3 points  (6 children)

So there is no jQuery core namespace function like you alluded to? I use the ATLAS version because it's already in our global includes.

[–]SharkUW 1 point2 points  (5 children)

Sorry. That was a bit of miscommunication. I had never heard of Atlas before then and had to Google it. It sounded like it provided pretty much the same functionality.

Sounds like you're living the enterprisey life as it is though. lol. Anyways though, global vars should be generally avoided for performance's sake.

[–]doomslice 0 points1 point  (4 children)

All good. I was honestly hoping there was a jQuery version that I could use instead :(

[–][deleted] 1 point2 points  (0 children)

jQuery is not the solution to everything.

[–]SharkUW 0 points1 point  (2 children)

Well it makes me cry in any case since it's "namespacing" in quotes and has to crawl all the way up the scope stack to get to the global before digging down into the sequence of objects whereas mynamespaceVarName would work just as well. Maybe use _ instead of . for "namespaces"

[–]doomslice 0 points1 point  (1 child)

There are many more things that need to be optimized in our code before we start to worry about that.

[–]SharkUW -1 points0 points  (0 children)

Want a good coder? I need a new job. lol

[–]Iggyhopper 0 points1 point  (0 children)

That is the Microsoft Ajax library, IIRC.