Availability
JavaScript 1.5; JScript 5.5; ECMAScript v3
Synopsis
object.hasOwnProperty(propname)Arguments
propname
A string that contains the name of a property of
object.
Returns
true 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.
Description
As 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.
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
See Also
Function.prototype, Object.propertyIsEnumerable( ); Chapter 8
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.