The Object Class : Object « Object Oriented « JavaScript Tutorial






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:

  1. constructor -- For the Object class, this points to the native Object() function.
  2. 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.









25.2.Object
25.2.1.The Object Class
25.2.2.Object()
25.2.3.Object.constructor
25.2.4.Object.eval()
25.2.5.Object.prototype
25.2.6.Object.toSource()
25.2.7.Object.toString()
25.2.8.Object.unwatch()
25.2.9.Object.valueOf()
25.2.10.Object.watch()
25.2.11.Add method to Object class