Ken Johanson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromKen Johanson
ToMe
SubjectYour javascript tutorial
Date29 April 2005 23:09
Excellent work!! I noticed one thing that I didnt see prominately listed:
IE doesn'y respect the langaue/version attribute of a javascript script tag.
It always treat "==" evals on 'empty' ojects (null==undefined==0, etc in
the pre-1.2 fashion.

The following shows this difference if you swap in/out the 1.2 version,
comparing on Gecko and IE:

<html>
<script language="Javascript1.2">
   document.writeln(null==undefined);
   document.writeln(0=="");
   document.writeln(null=="");
   document.writeln(0==undefined);
   document.writeln(0==null);
   document.writeln(""==undefined);
   document.writeln("<br>");
     var a;
   var b = null;
   var c = undefined;
   var d = 0;
   var e = "";
   var f = "a";
     document.writeln(a?"y":"n");
   document.writeln(b?"y":"n");
   document.writeln(c?"y":"n");
   document.writeln(d?"y":"n");
   document.writeln(e?"y":"n");
   document.writeln(f?"y":"n");
     document.writeln(a && b && c && d && e ? "y" : "n");
   document.writeln(a || b || c || d || e ? "y" : "n");
</script>
</html>

Actually, 1.2 is the problem. Both browsers empty== behave the same using
1.3. So maybe 1.2 should be discouraged for the dissimilar behavior and
fact that most browsers support 1.3+


Thanks again,
Ken
FromMe
ToKen Johanson
SubjectRe: Your javascript tutorial
Date29 April 2005 23:35
Ken,

> comparing on Gecko and IE:

And let's not forget Opera (the browser I use myself) and the others as
well ...

> listed: IE doesn'y respect the langaue/version attribute of a javascript
> script tag. It always treat "==" evals on 'empty' ojects
> (null==undefined==0, etc in the pre-1.2 fashion.

Indeed. I should update the page to say that. In fact, Internet Explorer is
not the only one with that behaviour. Opera, Safari/OmniWeb and Konqueror
all behave the same way. So only Gecko is the odd one out.

In my mind, they are correct to ignore the version number, since it is just
a leftover from Netscape 4, and there are in fact no official standards for
the version numbers (they conflict with ECMAscript, which is the actual
standard). The language attribute is in fact deprecated according to the
HTML spec.

Still, I will update the page. Thanks for bringing it to my attention.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromKen Johanson
ToMe
SubjectRe: Your javascript tutorial
Date29 April 2005 23:47
Tarquin, did they really deprecate the language attribute of script? If so,
how would alternate langaues be indicated (though the type (mime) attribute
I presume), and version compatibilities be handled, e.g. scripts containing
newer language features not supported, are ignored? Did they delgate that
to the runtime to check versions (makes sense). That begs the question "How
do you tell from javascript what langaue version is supported?" - obvioulsy
using the agent version to do that would be half-sass at best  :-)

These might all be mentionable points as well - I've doing this since NS3
and didn't know about the empty type's == operator disparity for 1.2 until
just today :-)

Thanks!
Ken
FromMe
ToKen Johanson
SubjectRe: Your javascript tutorial
Date30 April 2005 00:09
Ken,

> Tarquin, did they really deprecate the language attribute of script?

yep.
http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1

> how would alternate langaues be indicated (though the type (mime)

for things like text/javascript text/vbscript etc, yes.

> and version compatibilities be handled

Basically, they aren't. But using the language attribute is no better
anyway. IE 5 does not support 1.3, so you would have to use 1.2. But IE
supports try...catch while Netscape 4 does not. Early Netscape 4 does not
support functions that only sometimes return values, and does not allow the
'this' keyword to work in methods that are declared inline. Newer Netscape
4 versions do. But all these browsers claim to support javascript 1.2.

The JavaScript version numbers are just arbitrary. They do not relate to
actual capabilities. Only the ECMAscript spec says what the capabilities of
each ECMAscript version should be, but the language attribute never
reflected that, so it was essentially useless anyway.

Tarquin
FromKen Johanson
ToMe
SubjectRe: Your javascript tutorial
Date30 April 2005 00:30
Very enlightening, thank you very much!

Take, and again, kudos!!! Probably the best set of articles I've seen!

Best,
-Ken
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.