[thelist] javascript syntax

Liorean Liorean at user.bip.net
Sat May 11 15:17:01 CDT 2002


At 10:32 2002-05-11 -0700, .jeff wrote:
>loriean,

You spell it wrong. Liorean it is. This is the second time now, so please
don't make a habit of it.


>actually, there's not.  your version is only shorter because you haven't
>gone to the trouble of doing a check for support of the test() method before
>using it.  any browser that encounters that line of code and doesn't support
>the test() method will throw an error.  that's a lazy and irresponsible
>approach.

I consider the browsers unable to understand it a minor loss.


>i guess i fail to see the point of using a regex when a simple substring
>match will suffice and work in more browsers without method support
>detection being necessary.

Why go to length about third generation support instead of rely on fourth
and fifth generation.


>add that check and now my version is shorter.  so which is it gonna be now?

Well, the check can be done using OR, making the entire thing:
   !RegExp||/mac/i.test(navigator.platform)&&(top.location='/ns/index.htm')
Now, that is still smaller than
   if(navigator.platform.toLowerCase().indexOf('mac')!=1)top.location='/ns/index.htm';

(Minor difference now... but still, why remain at third generation when
it's almost gone from the market?)


>so, as far as that goes, you could probably get just as useful information
>from the userAgent property.

But the UAString isn't guaranteed to have the information in it, if you
take the browsers you mention into concern.


>there's a vast difference between pretty consistent and universally
>supported.
>that was my point.

Point noted.


>i'm fully aware of short-circuit evaluation and how it works.  however, a
>statement of assignment will always evaluate to true so i don't see the
>point of the second half of the conditional in your example.  however, had
>you been doing a using an equality operator (==) i might be able to
>understand, though it doesn't make much sense to use a test of the location.

First of all, no, not all values will evaluate to true. 0, false, null, and
undefined will evaluate to false. Second, I use it instead of an if
statement in this case. The condition is the first expression, the second
expression is the block to be run if true. If you get lengthy "if this so
that then if this so something else..." statements you can really cut them
down by using short-circuiting.


>i've tested it in all varieties i'm aware of.  nn4 has issues with relative
>paths to background images within an external stylesheet, but i've never
>encountered a problem with mis-interpreting a location change that is root
>relative.

Well, it still doesn't work at all without the protocol part in some
versions, but using a root relative url does force both the other behaviors
into root relative.

The problem was rather that if a location change in the file
http://www.example.com/example/index.html to the string
"sources/index.html" led some versions to
http://www.example.com/example/sources/index.html and some versions to
http://www.example.com/sources/index.html. In other words, it sometimes
treated the URL as root relative even if it wasn't.

// Liorean




More information about the thelist mailing list