AvailabilityJavaScript 1.5; JScript 5.5; ECMAScript v3 Synopsisobject.hasOwnProperty(propname) Arguments
Returnstrue if object has a noninherited property with the name specified by propname. Returns false if object does not have a property with the specified name or if it inherits that property from its prototype object. DescriptionAs explained in Chapter 8, 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. Examplevar 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 See AlsoFunction.prototype, Object.propertyIsEnumerable( ); Chapter 8 |