R
Randell D.
Folks,
I'm a newbie when it comes to JavaScript and whenever I visit a website
curiosity sometimes get's the better of me and I'll inspect some of their
code - It teaches me new things (either methods, or alternative solutions to
a problem). I'm not talking about pinching someone else's code - so don't
flame me.
I notice though that while taking a look at the source view of
http://news.independent.co.uk/uk/crime/ that there seemed to be some
javascript functions that were delcared twice - is this just bad programming
practice or is there something that I don't know about... I can program
reasonably well in PHP and a handful of other languages and I would have
expected either an error (that a function had already been delcared) or else
the second function would take precedance over the first.... An exerpt of
the source code follows to back up my example... I'm just wondering though
the reason - bad programmer or what?
I'd welcome comments...
Cheers
randelld
(*some* of the code is included below - note two functions called
storeCookie... why?)
<SCRIPT TYPE="text/javascript"><!--
function storeCookie(key,val) {
var age = 100*24*3600 * 1000; // ms in 100 days
storeCookieKey( key, val, age, true );
}//storeCookie
function storeCookie(key,val,age,reloadPg) {
var expDate = new Date();
var expTime = expDate.getTime() + age;
expDate.setTime( expTime );
document.cookie = key +"="+ val + "; expires="+ expDate.toGMTString() ;
if( reloadPg )
window.location.reload();
}//storeCookie
I'm a newbie when it comes to JavaScript and whenever I visit a website
curiosity sometimes get's the better of me and I'll inspect some of their
code - It teaches me new things (either methods, or alternative solutions to
a problem). I'm not talking about pinching someone else's code - so don't
flame me.
I notice though that while taking a look at the source view of
http://news.independent.co.uk/uk/crime/ that there seemed to be some
javascript functions that were delcared twice - is this just bad programming
practice or is there something that I don't know about... I can program
reasonably well in PHP and a handful of other languages and I would have
expected either an error (that a function had already been delcared) or else
the second function would take precedance over the first.... An exerpt of
the source code follows to back up my example... I'm just wondering though
the reason - bad programmer or what?
I'd welcome comments...
Cheers
randelld
(*some* of the code is included below - note two functions called
storeCookie... why?)
<SCRIPT TYPE="text/javascript"><!--
function storeCookie(key,val) {
var age = 100*24*3600 * 1000; // ms in 100 days
storeCookieKey( key, val, age, true );
}//storeCookie
function storeCookie(key,val,age,reloadPg) {
var expDate = new Date();
var expTime = expDate.getTime() + age;
expDate.setTime( expTime );
document.cookie = key +"="+ val + "; expires="+ expDate.toGMTString() ;
if( reloadPg )
window.location.reload();
}//storeCookie