Opera JavaScript Behavior--Enumerating Browser Object Properties Using for...in Statements

Note: This is not considered a flaw in the Opera browser.
There is no consistent behavior among other browsers that support JavaScript, and ECMA-262 does not dictate the mechanics of enumerating object properties.

The JavaScript code included in this document enumerates the properties of the navigator, window, and document objects, as well as those of a user-defined object, MyObject.

When this document is loaded in Netscape Navigator, each object provides several properties. When this document is loaded in Opera, however, each object provides either no properties at all or a small subset of those that actually exist, except for the user-defined object which displays all of its properties correctly.

As stated before, this is not considered an error in Opera. Microsoft Internet Explorer (version 3) behaves similarly, displaying no properties at all for the navigator, window, or document objects. Section 12.6.3 of the ECMA-262 specification, "The for..in statement," states that the enumeration of object properties is implementation-dependent.

Load this document in Opera, Netscape Navigator, and Microsoft Internet Explorer and compare results. The objects' properties are enumerated using JavaScript for...in statements similar to the following:

document.write ("<H3>navigator Object</H3>");
for (i in navigator)
{
    document.write("navigator." + i + " = " + navigator[i]+ "<BR>");
}
(Some style suggestions were added to the actual code in order to enhance readability.)

Demonstration


Discovered By

This behavior was discovered by Charles L. Taylor, who also prepared this example.

Last update: 11 Feb 1999 -- (Copyright) -- (Contact)