Bogus Global Variables
© 2011, Martin Rinehart
There are three issues here. The first is that you may be creating lots of global variables, no matter how careful your namespacing. The second is that Firefox has gone its own way. The third is yet another MSIE deviation.
First, if you create a DOM element, assign it an ID and append it to the DOM, you have created a global variable. The name of the global is the ID of the DOM element. It's value is a reference to the DOM element—the same reference that is returned by
document.getElementById( ... ).
Second, this is true in all browsers except Firefox starting with 3.6.13. Mozilla has stopped adding this pollution to the global namespace. Good thinking, Mozilla.
Third, MSIE goes its own way when it is time to remove the DOM element that created the global variable. Remove the element from the DOM and the bogus global is "undefined" in all browsers except MSIE. In MSIE the bogus global is "unknown," a type that I don't know.
Feedback: MartinRinehart at gmail dot com
# # #