May 3, 2000 - Detecting Object-Property Relationship | WebReference

May 3, 2000 - Detecting Object-Property Relationship

Yehuda Shiran May 3, 2000
Detecting Object-Property Relationship
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

IE5.5 introduced a score of new operators and methods for detecting various object-property relationships. The in operator checks if a given property is defined for a given object. Suppose the object line is of type Array:

line = new Array("aaa", "bbb", "ccc", "ddd", "eee");

We know that the object line inherited the Array's properties such as its length. If we check whether length is in line (length in line), we should get a true value. Notice that the array should not be empty, or else the returned answer will be a false value.

Similarly, the method hasOwnProperty does exactly what the in operator does. The expression:

line.hasOwnProperty(length)

should return a true value.

The method propertyIsEnumerable() checks, again, that a given property belongs to a given object. Once it belongs, it is automatically enumerable in for...in loops. The for...in loop loops through the existing properties of a given object. The check line.propertyIsEnumerable(length) should return a true value.