title | layout | author | authorurl |
---|---|---|---|
The javascript super genius |
post |
Jon Beebe |
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!
{% highlight javascript %} // filename:windows.js // javascript lib. for making pop up windows // richard e. walker, suuuupppppppppppppppppperrrrrrrrrrrrrr geennnnnnnnnnnnnniuuuuussssssss {% endhighlight %}
Later we find this comment, also around some embebbed js functions:
{% highlight html %}
{% endhighlight %}
Now that we've established the author as a certifiable genius, what does he have to offer us?
- Demonstrating the genius' way of padding numbers
{% highlight javascript %} function twoPlaces( num ) { if ( num < 10 ) num = '0' + num; return num; } {% endhighlight %}
- Demonstrating the proper use mixing explicit/implied open/close curly brackets. All geniuses will agree this is a best-practice.
{% highlight javascript %} 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 ...
} {% endhighlight %}
- 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.
{% highlight javascript %} 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;
}
}
} {% endhighlight %}
All of this inside a web-app utilizing 5 iframes, cookies, and javascript in a single page to simulate ajax-like behavior.