Perfect example of whats wrong with JS

This is from the Require.js library which is very useful, and solves a lot of find when using JS.

    //Alias for caja compliance internally -
    //specifically: "Dynamically computed names should use require.async()"
    //even though this spec isn't really decided on.
    //Since it is here, use this alias to make typing shorter.
    req = require;


Use this alias to make your development time noticeably shorter by doing that? Are you really clocking out earlier? Calling it a half day most of the time after that huge time saver?

No it’s just a pointless and at worst confusing inconsistent modification to the code from only that point forward to anyone looking at it.

Another Example

This also irks me. I’m getting some error, and im trying to dive into the multi-thousand line (literally) file, and figure out whats going wrong / learn the module better. When I go to the line in question, i scroll up to find this:

 main = function (name, deps, callback, config, contextName, relModuleName) {
        //Grab the context, or create a new one for the given context name.
        var context, newContext, loaded, pluginPrefix,
            canSetContext, prop, newLength, outDeps, mods, paths, index, i,
            deferMods, deferModArgs, lastModArg, waitingName, packages,

        contextName = contextName ? contextName : (config && config.context ? config.context : s.ctxName);

// What the freaking hell is s?       
context = s.contexts[contextName];

        if (name) {
                        // Pull off any plugin prefix.
            index = name.indexOf("!");
            if (index !== -1) {
                pluginPrefix = name.substring(0, index);
                name = name.substring(index + 1, name.length);
            } else {
                //Could be that the plugin name should be auto-applied.
                //Used by i18n plugin to enable anonymous i18n modules, but
                //still associating the auto-generated name with the i18n plugin.

//				console.log(" context.defPlugin[name]", this);
                pluginPrefix = context.defPlugin[name];

            //If module already defined for context, or already waiting to be
            //evaluated, leave.
            waitingName = context.waiting[name];
            if (context && (context.defined[name] || (waitingName && waitingName !== ap[name]))) {

What the hell is ‘s’? !! This left my struggling to find it by doing ctrl+f, for the most popular letter in the alphabet.

Seriously i waste so much time on this kind of junk when I code in javascript – it really takes the fun of it.

One thought on “Perfect example of whats wrong with JS”

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.