Section 24.144. Object.propertyIsEnumerable( ): will property be seen by a forin loop?


24.144. Object.propertyIsEnumerable( ): will property be seen by a for/in loop?

ECMAScript v3

24.144.1. Synopsis

object.propertyIsEnumerable(propname)

24.144.1.1. Arguments

propname

A string that contains the name of a property of object.

24.144.1.2. Returns

true 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.

24.144.2. Description

The 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 it works only for local properties of an object and does not provide any way to test the enumerability of inherited properties.

24.144.3. Example

 var 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 

24.144.4. See Also

Function.prototype, Object.hasOwnProperty( ); Chapter 7




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net