Core JavaScript 1.5 Reference:Global Objects:Object
From MDC
Contents |
Summary
Creates an object wrapper.
Syntax
new Object( [ value ] )
Parameters
- value
- Any value.
Description
The Object constructor creates an object wrapper for the given value. If the value is null or undefined, it will create and return an empty object, otherwise, it will return an object of type that corresponds to the given value.
When called in a non-constructor context, Object behaves identically.
Properties
For properties inherited by Object instances, see Properties of Object instances.
- __parent__
- Non-standard
- Points to an object's context.
- __proto__
- Non-standard
- Points to the object which was used as prototype when the object was instantiated.
- prototype
- Allows the addition of properties to all objects of type Object.
Properties inherited from Function.prototype
caller, constructor, length, name
Methods
For methods inherited by Object instances, see Methods of Object instances.
Although the Object object contains no methods of its own, it does inherit some methods through the prototype chain.
Methods inherited from Object.prototype
__defineGetter__, __defineSetter__, hasOwnProperty, isPrototypeOf, __lookupGetter__, __lookupSetter__, __noSuchMethod__, propertyIsEnumerable, unwatch, watch
Object instances
All objects in JavaScript are descended from Object; all objects inherit methods and properties from Object.prototype, although they may be overridden. For example, other constructors' prototypes override the constructor property and provide their own toString methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.
Properties
- constructor
- Specifies the function that creates an object's prototype.
Methods
- __defineGetter__
- Non-standard
- Associates a function with a property that, when accessed, executes that function and returns its return value.
- __defineSetter__
- Non-standard
- Associates a function with a property that, when set, executes that function which modifies the property.
- eval
- Deprecated
- Evaluates a string of JavaScript code in the context of the specified object.
- hasOwnProperty
- Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
- isPrototypeOf
- Returns a boolean indication whether the specified object is in the prototype chain of the object this method is called upon.
- __lookupGetter__
- Non-standard
- Returns the function associated with the specified property by the __defineGetter__ method.
- __lookupSetter__
- Non-standard
- Returns the function associated with the specified property by the __defineSetter__ method.
- __noSuchMethod__
- Non-standard
- Allows a function to be defined that will be executed when an undefined object member is called as a method.
- propertyIsEnumerable
- Returns a boolean indicating if the internal ECMAScript DontEnum attribute is set.
- toSource
- Non-standard
- Returns string containing the source of an object literal representing the object that this method is called upon; you can use this value to create a new object.
- toString
- Returns a string representation of the object.
- unwatch
- Non-standard
- Removes a watchpoint from a property of the object.
- valueOf
- Returns the primitive value of the specified object.
- watch
- Non-standard
- Adds a watchpoint to a property of the object.
Examples
Example: Using Object given undefined and null types
The following examples return an empty Object object:
var o = new Object(); o = new Object(undefined); o = new Object(null);
Example: Using Object to create Boolean objects
The following examples return Boolean objects:
o = new Object(true); // equivalent to o = new Boolean(true); o = new Object(Boolean()); // equivalent to o = new Boolean(false);