/Ugly/ + 'JavaScript'

A place for ugly, silly, or just-plain-crap JavaScript.

The javascript super genius

All credit for this code goes to Richard E. Walker. Inside our html code we see the following. Note it’s not in a javascript file, but rather the contents are embedded into the html. Genius!

// filename:windows.js
// javascript lib. for making pop up windows
// richard e. walker, suuuupppppppppppppppppperrrrrrrrrrrrrr geennnnnnnnnnnnnniuuuuussssssss

Later we find this comment, also around some embebbed js functions:

<!--  this is a javascript library...
filename:javascript.js

 Richard E. Pluribus Unum Walker
 suuuuuuuuuupppperrrrr geeeeeeeeennniuuuuusssss

-->

Now that we’ve established the author as a certifiable genius, what does he have to offer us?

1) Demonstrating the genius’ way of padding numbers

function twoPlaces( num )
{
    if ( num < 10 ) num = '0' + num;
    return num;
}

2) Demonstrating the proper use mixing explicit/implied open/close curly brackets. All geniuses will agree this is a best-practice.

function DebugObject(winOUT,debugOBJ) {
if (! debugOBJ)
        return(false);

if ( winOUT.document ) {
        var dOUT = winOUT.document;
} else if (winOUT.contentDocument) {
        var dOUT = winOUT.contentDocument;
} else {
        alert("cant find browser document");
        return(false);
} // end if

...more of the same mixture ...

}

3) Liberal use of tabs when formatting code, creating a zen-like editing experience (on 8-space-tab setups). Converted to spaces here to ensure proper viewing.

function SetStartTimesFunc( myDate )
{
        var wantedTime        =        document.getElementById( 'SetStartTimes' );
        CheckOnTimeInput( wantedTime );
        var inputs        =        document.getElementsByTagName( 'INPUT' );

        for ( var i = 0; i < inputs.length; i++ )
        {
                var thisInput        =        inputs[i];

                parts                =        thisInput.id.split(':');

                if ( parts[0] == 'AuctionStart' )
                {
                        thisInput.value                =        myDate + ' ' + wantedTime.value;
                }
        }
}

All of this inside a web-app utilizing 5 iframes, cookies, and javascript in a single page to simulate ajax-like behavior.

Posted by Jon Beebe on 16 Sep 2011 | linky

Subscribe or follow @UglyJS!
.........
Fork then send a pull request to contribute.