Section 24.142. Object.hasOwnProperty( ): check whether a property is inherited


24.142. Object.hasOwnProperty( ): check whether a property is inherited

ECMAScript v3

24.142.1. Synopsis

object.hasOwnProperty(propname)

24.142.1.1. Arguments

propname

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

24.142.1.2. Returns

true if object has a noninherited property with the name specified by propname; false if object does not have a property with the specified name or if it inherits that property from its prototype object.

24.142.2. Description

As explained in Chapter 9, JavaScript objects may have properties of their own, and they may also inherit properties from their prototype object. The hasOwnProperty( ) method provides a way to distinguish between inherited properties and noninherited local properties.

24.142.3. Example

 var o = new Object( );            // Create an object o.x = 3.14;                      // Define a noninherited local property o.hasOwnProperty("x");           // Returns true: x is a local property of o o.hasOwnProperty("y");           // Returns false: o doesn't have a property y o.hasOwnProperty("toString");    // Returns false: toString property is inherited 

24.142.4. See Also

Function.prototype, Object.propertyIsEnumerable( ); Chapter 9




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