It is just a utility function which returns me an element by its id attribute. Nothing special. But then... There is a line saying:var Utils = new Object();
Utils.byId = function( id ) {
if( document.all ) {
return document.all[ id ];
}
return document.getElementById( id );
}
It works. Well, it worked in Firefox and Opera. But in IE, there was an error saying something like: object doesn't have that property... I can't remember now (I'm on my Ubuntu linux PC now). It took me half an hour of experiments before I found the error. The error was the word var. The line:panorama = Utils.byId( "panorama" );
var panorama = Utils.byId( "panorama" );
don't work without the "var".When I was studying Javascript, in the manual it was said that if I use var for declaring variables -- they were local variables. Without var they are global variables. Since panorama in my javascript is a global variable, I decided to delete the "var". But IE didn't like it.
Why?
This is because of IE's buggy Global Namespace pollution.
ReplyDeleteSince "panorama" was an ID, IE added it as a global object called panorama. Thus when you try to use "var" you are trying to re-declare a circular reference.
See/track the bug here:
http://webbugtrack.blogspot.com/2007/09/bug-162-global-namespace-pollution-in.html
Now I understand, thanx Bradley!
ReplyDeleteBTW, nice blog! Why don't you allow comments there?