Checks whether an object has a locally defined (non-inherited) property with a specific name.
<script type= "Text/javascript" >
var o = new Object ();
O.name= "Tom";
Alert (O.hasownproperty ("name")); True
Alert (O.hasownproperty ("Age")); False
</script>
2.isPrototypeOf ()
Grammar
object. isprototypeof (o)
Parameters
-
o
-
Any object.
return value
Returns true if object is a prototype of O. Returns False if O is not an object, or if object is not a prototype of O.
Describe
JavaScript objects inherit the properties of the prototype object. The prototype of an object is referenced by the prototype property of the constructor that is used to create and initialize the object. The isPrototypeOf () method provides a way to determine whether an object is a prototype of another object. This method can be used to determine the class of an object.
Example
var o = new Object ( ); Create an Object Object.prototype.isPrototypeOf (o) //True:o is an object Function.prototype.isPrototypeOf (o.tostring); True:tostring is a function of Array.prototype.isPrototypeOf ([+]); True: [All-in-one] is an array//the following is another way to perform the same test (O.constructor = = Object); True:o is created with Object ( ) constructor (O.tostring.constructor = = Function); True:o.tostring is a function/prototype is the object itself to the prototype object. The following call returns the true//description function following the Function.prototype and Object.prototyp properties. Object.prototype.isPrototypeOf (Function.prototype);
3.ProertyIsEnumerable ()
Grammar
object. propertyisenumerable (propname)
Parameters
-
propname
-
A string that contains the name of the object prototype.
return value
Returns true if object has a non-inherited property named PropName, and the property is enumerable (that is, it can be enumerated with the for/in Loop).
Describe
Use the For/in statement to iterate through an object's "enumerable" properties. But not all of the properties of an object are enumerable, and the properties that are added to the object through JavaScript code are enumerable, and the predefined properties of the inner object, such as methods, are usually non-enumerable. The Propertylsenumerable () method provides a way to differentiate between enumerable and non-enumerable properties. Note, however, that the ECMAScript standard stipulates that the propertyIsEnumerable () method does not detect the prototype chain, which means that it applies only to the local properties of the object and cannot detect the enumerable of inherited properties.
Example
var o = new Object ( ); Create an object o.x = 3.14; Define-a property o.propertyisenumerable ("X"); True Property x is a local, enumerable o.propertyisenumerable ("Y"); False:o has no attribute yo.propertyisenumerable ("toString"); The FALSE:TOSTRLNG attribute is an inherited Object.prototype.propertyIsEnumerable ("toString"); False: Enumeration of the
Bug
When the standard limit propertylsenumerable () method can only detect non-inherited attributes, it is obviously wrong. Internet Explorer 5.5 implements this method by standard. The NESTACPE 6.0 implementation of the propertyIsEnumerable () method takes into account the prototype chain. While this method is preferable, it conflicts with the standard, so Netscape 6.1 modifies it so that it matches IE 5.5. Because of this error in the standard, this method is not so useful.