August 15, 2000 - Expnado Properties | WebReference

August 15, 2000 - Expnado Properties

Yehuda Shiran August 15, 2000
Expando Properties
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

The default behavior of Internet Explorer is that you can add arbitrary properties to any object on the page. These properties are called expando properties. Starting from Version 5, you can protect yourself from creating arbitrary properties. This self protection prevents you from creating new properties when you intend to set existing properties, but fail because of typos and wrong cases. For example, if you want to set the borderColor property of a style object and you type instead bordercolor, a new expando property will be created. As a consequence, the border color will not be changed according to your specifications and you will have difficult time figuring out why.

To protect you from doing such mistakes, you should set the expando property to false:

document.expando = false;
To reset it back:

document.expando = true;
If you try to create an arbitrary property when document.expando is false, you'll get an error message that the object does not support such property. The following two lines yield no error (myDiv is the ID of a DIV element somewhere on the page):

document.expando = true;
myDiv.myProperty = myValue;
while the following two lines yields an error message telling you that the object myDiv does not support the property myProperty:

document.expando = false;
myDiv.myProperty = myValue;