Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

The Object Class

The Object class in JavaScript is similar to java.lang.Object in Java. The Object class in JavaScript is the base class for all JavaScript classes. All the properties and methods of the Object class are also present in the other classes. The Object class has the following properties: constructor -- For the Object class, this points to the native Object() function. prototype -- For the all classes, this returns an instance of Object by default. The Object class also has several methods: object.hasOwnProperty(property) Determines if a given property exists for the object. The property must be specified as a string. For example, o.hasOwnProperty("name"). object.isPrototypeOf(object) Determines if the object is a prototype of another object. propertyIsEnumerable(property) Determines if a given property can be enumerated by using the for...in statement. object.toString() Returns a primitive string representation of the object. object.valueOf() Returns the most appropriate primitive value of this object. For many classes, this returns the same value as toString(). Each of the properties and methods listed previously are designed to be overridden by other classes.