Phat G5 (G3) said the following on 6/4/2007 12:39 PM:
That script is a consolidation of 2 different scripts out on the net.
Most of what you find "on the net" isn't worth copying though.
I went thru it and deleted a bunch of crap that was old.
Then why is there a branch for a browser that is so outdated that it is
a pain to even find the last version of it? (Netscape 4). Typically, if
you see code that has if(document.layers) then you can rest assured it
is 10 years old or so.
It started working and so I have to stop and get onto
more crucial parts and come back to it later on.
As long as its a goal to get it updated, more efficient and quicker,
then there is nothing wrong with it.
What specifically from the faq are you referring to? What really makes it
all that bad?
The first thing I do when looking at code from the web is do a search
for the word "eval" and typically if you find it then it isn't very well
written. And it is true in this case. In the displayTime function you
have this code:
else if (document.layers)
{
var x = eval('document.layers.'+ obj);
var xWithoutEval = document.layers[obj];
//code here
}
else if (document.all)
{
var x = eval(obj)
var xWithoutEval = document.all[obj];
//code here
The advantage is that you aren't calling eval which starts a separate
instance of the compiler/engine and makes it more efficient. The other
problem with eavl(obj) is that it depends on a flaw in IE where it makes
the ID/NAME attribute a global variable and if a browser exists that
takes the document.all branch that doesn't make it a Global then it will
error out when that error can be easily avoided.
The function daysInMonth has this code:
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))
DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))
DaysInMonth = 29;
The problem with that code will manifest itself every 400 years as leap
year is not a simple matter of dividing by 4, every 400 years there is
no leap day (test it for 2000).
John also won't like your date format or the fact that you used AM/PM
instead of a 24 hour clock.
There is probably more but I got tired of looking.