Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

overload or replace function?

Status
Not open for further replies.

elck

Programmer
Apr 19, 2004
176
NL
In a website for a client I created this function:
function reload(a) {
location.href="index.php?pag=" + a; }


Of course I shouldn't have as there is already a function:
location.reload([bReloadSource] )

But I didn't realise that at the time.

I tested the script and it worked as I expected in Iexplorer 6.028 and also in Ieplorer 5.5
So I guess my function replaced the predefined function.

Then, at my clients computer all pages worked fine, except page 1. It took me days before I realised that I had used a reserved name for my function and then another night before I saw what had happened: In the client's pc the function I wrote was seen as an overload function that was only called for arguments other than 'true' or 'false', 1 or 0.

I find this behaviour very bizar. How can the same function, on one version of IEx be seen as a replacement and on another as an overload???

Any explanations or similar experiences?
 
Because each browser (and version) is different from all other browsers (and versions). Some variants may be more forgiving than others... or function differently "under the hood". This is especially true when looking at differences between major browser version revisions (IE4 vs IE5, IE5 vs IE6).

I find that I just steer comepletely away from using reserved words (usually I place "my" before any function or variable name to ensure this).

Anyone else?
Jeff
 
Of course you are right, Jeff and I will use the my prefix too from now on. The really weird thing is that my clients browser was a 6.0.xx version too!
 

I cannot see how using a function name of "reload" would cause problems.

Surely your function wouldn't overwrite the "location.reload" method, as your function was global to the window, not the location object.

Let us know if Jeff's fix works or not, because I'd be surprised if it makes a difference.

Dan
 
Oh yes, certainly it works.
I agree that the scope is different from the location function, so I guess it is an ordinary bug.

My client is using xp-home edition, an operating system that I profoundly hate, but I don't think that was the problem?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top