AvailabilityJavaScript 1.5; JScript 5.5; ECMAScript v3 Synopsisobject.propertyIsEnumerable(propname) Arguments
Returnstrue if object has a noninherited property with the name specified by propname and if that property is "enumerable," which means that it would be enumerated by a for/in loop on object. DescriptionThe for/in statement loops through the "enumerable" properties of an object. Not all properties of an object are enumerable, however: properties added to an object by JavaScript code are enumerable, but the predefined properties (such as methods) of built-in objects are not usually enumerable. The propertyIsEnumerable( ) method provides a way to distinguish between enumerable and nonenumerable properties. Note, however, that the ECMAScript specification states that propertyIsEnumerable( ) does not examine the prototype chain, which means that it only works for local properties of an object and does not provide any way to test the enumerability of inherited properties. Examplevar o = new Object( ); // Create an object o.x = 3.14; // Define a property o.propertyIsEnumerable("x"); // true: property x is local and enumerable o.propertyIsEnumerable("y"); // false: o doesn't have a property y o.propertyIsEnumerable("toString"); // false: toString property is inherited Object.prototype.propertyIsEnumerable("toString"); // false: nonenumerable BugsThe specification is apparently in error when it restricts propertyIsEnumerable( ) to check only noninherited properties. Internet Explorer 5.5 implements this method as specified. Netscape 6.0 implements it so that it does consider the prototype chain. Although this is the way the method was probably intended to work, it violates the specification, and Netscape 6.1 has been modified to match the IE 5.5. Because of the error in the specification, this method is less useful than it should be. See AlsoFunction.prototype, Object.hasOwnProperty( ); Chapter 8 |