Object object (Object/core)

An object of the class "Object".

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Netscape Enterprise Server - 2.0
Opera - 3.0
JavaScript syntax:-myObject = new Object()
-myObject = Object
Object properties:__parent__, __proto__, constructor, name, prototype
Object methods:assign(), eval(), hasOwnProperty(), isPrototypeOf(), propertyIsEnumerable(), toLocaleString(), toSource(), toString(), unwatch(), valueOf(), watch()

An instance of the class "Object" is created by using the new operator on the Object() constructor. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms.

All properties and methods of the prototype are available as if they were part of the instance.

An Object is a member of the type Object. It is an unordered collection of properties, each of which may contain a primitive value, another object, or a function.

The constructor is invoked by the new operator or by calling it as a Constructor function. For example:

new String("Some Text");

This will create a new object of the String type. You can invoke the constructor without the new operator but the consequences will depend on the constructor as to what it will yield as a result. In the case of the String data type, the constructor could be invoked like this:

String("Some Text");

However, you would get a primitive string as a result from this and not a String object. JavaScript is somewhat forgiving and you may not notice this happening until later on when it becomes important that you have a String object and not a simple string.

Because this object is the topmost parent object in the prototype inheritance hierarchy, all other object classes inherit its methods and properties. However, in some cases they will get overridden or nulled out.

DOM level 2 adds the following properties:

contentDocument

Although JavaScript is object-based, it does not support true object-oriented classes such as the ones you find in C++, Smalltalk, Java, or Objective C. Instead, it provides Constructor mechanisms, which create objects by allocating space for them in memory and assigning initial values to their properties.

All functions, including constructors, are themselves objects. However, not all objects are constructors. Each constructor has a Prototype property that is used to facilitate inheritance based on the prototype. It also provides for shared properties which is similar to but not the same as the Class properties that you find in true object-oriented languages.

Externally, the objects in JavaScript exhibit most of the attributes of a class-based object-oriented system and some commentators argue that this qualifies JavaScript as being a genuine object-oriented system. However I think the following points declassify it as a truly object-oriented system, meaning that it is an "object-like" system:

It's a close enough call that JavaScript 2.0 may well move it into the class-based object-oriented category at which time the prototype inheritance would be replaced with super-class/sub-class mechanisms and the arguments become null and void.

Warnings:

See also:Aggregate type, Array object, Boolean object, Date object, delete, Function object, Math object, Native object, Number object, Object, OBJECT object, Object(), Object(), Object.Class, Object.prototype, String object, userDefined object

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
__parent__1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
__proto__1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
constructor1.1 1.13.0 1.03.0 3.04.0 3.023.0 3.0 n/a2 2 n/a n/a n/a-
name n/a5.5 5.5 n/a5.5 5.5 n/a n/a n/a n/a n/a n/a-
prototype1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a2 2 n/a n/a n/aWarning , ReadOnly, DontDelete, DontEnum

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
assign()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning , Deprecated
eval()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.02.0 2.0 n/a n/a n/a n/aWarning , Deprecated
hasOwnProperty()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
isPrototypeOf()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
propertyIsEnumerable()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
toLocaleString()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/aWarning
toSource()1.3 1.33.0 3.04.06 4.064.0 4.0 n/a n/a n/a n/a n/a n/aWarning
toString()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a2 2 n/a n/a n/a-
unwatch()1.2 1.2 n/a4.0 4.0 n/a n/a3.0 3.0 n/a n/a n/a n/aWarning
valueOf()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.02.0 2.02 2 n/a n/a n/a-
watch()1.2 1.2 n/a4.0 4.0 n/a n/a3.0 3.0 n/a n/a n/a n/aWarning

Cross-references:

ECMA 262 edition 2 - section - 4.2.1

ECMA 262 edition 2 - section - 4.3.3

ECMA 262 edition 2 - section - 10.1.5

ECMA 262 edition 2 - section - 15.2

ECMA 262 edition 3 - section - 4.2.1

ECMA 262 edition 3 - section - 4.3.3

ECMA 262 edition 3 - section - 10.1.5

ECMA 262 edition 3 - section - 15.2

O'Reilly JavaScript Definitive Guide - page - 44

Wrox Instant JavaScript - page - 28