OK, that's clear. You are right, I should have remembered from C which
haven't used in a very long time. I know || is usually 'or' but I thought it
might have been like perl where :: gets a class.
Anyway, thanks again. Apart from the usual cross-browser hassles (which are
driving me absolutely crazy) it should be plain sailing now. Famous last
words more like.
Walter
-----Original Message-----
From: staffslug-bounces(a)staffslug.org.uk
[mailto:staffslug-bounces@staffslug.org.uk] On Behalf Of David Boucher
Sent: 18 February 2010 22:34
To: staffslug(a)staffslug.org.uk
Subject: Re: [Staffslug] Javascript Problem
walt wrote:
Well fantastic. I am very grateful and shall be using your version.
But, what does this mean:
var event e || window.event;
which is what I have used as apposed to:
if (!e) var e = window.event;
your version.
The top version is a short cut really, the end result is the same for both.
The first version is saying "create a variable called 'event' and assign
it the value of the variable 'e', if that variable has a value, or the
value of 'window.event', if that has a value. If both variables have a
value then 'e' will be used as that comes first. The '||' means or but
you probably know that.
The second version is saying "If the variable 'e' does not have a value
(the '(!e)' bit) then create a variable e and assign it the value of
'window.event'.
When I say "has a value" I mean that the variable is initialised and has
a value other than null, false or 0. In Javascript such a value is
considered logically 'true', with null, false or 0 being considered
'false'. Many other programming languages use a similar idea, C being
the most well known.
Either version will work, although personally, I would use the second
one as it's a bit clearer.
_______________________________________________
Staffslug mailing list
Staffslug(a)staffslug.org.uk
http://lists.staffslug.org.uk/mailman/listinfo/staffslug