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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does if ("".replace) do???

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Hi,

I'm curious to know what this if-statement means (javascript):

Code:
if ("".replace)
{
}

I can't think of anything....
Bet it's something simple, but I can't figure it out!

T.I.A.

Quasibobo

Don't eat yellow snow!
 

It tests for the presence of the replace method of the string object.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Isn't Replace a standard function in javascript? Or are there browsers who don't support javascript? Why should this be tested?

Don't eat yellow snow!
 
Different browser manufacturers implement their own versions of JavaScript (or ECMAScript or JScript or whatever you wish to call it). They also implement different features at different times.

So this might have been a way of testing for a certain browser version, or it might have been because the user didn't want to assume the replace method existed, or for any number of reasons.

Without contacting the original author of that code, we can only speculate as to why they coded it.

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
OK... thanks, I found this in a somewhat older script (but partly usefull to me and no original author).

But I think I can savely remove this statement,I already altered most of the script (no special javascript-functions...) to the script I wanted.

Don't eat yellow snow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top