Object
object constructorS2C Home « Globals « Object
In JavaScript you create an object instance using the constructor Object
.
Description
Creates an Object
wrapper.
Syntax
Signature | Description |
---|---|
var anObject = new Object([value]); | Creates an Object wrapper. |
Parameters
Parameter | Description |
---|---|
value | An optional initial value for the object.
|
Class Properties
Class Property | Description |
---|---|
prototype | Enables property assignment to objects of type Object and is inherited by every object. |
Instance Properties
Instance Property | Description |
---|---|
constructor | Returns a reference to the function that created the prototype and is inherited by every object. |
Class Methods
None.
Instance Methods
By using methods of the Object
object we can also access elements of numbers, manipulate numbers after creation and even create new numbers from existing numbers.
Instance Method | Description |
---|---|
Getter (Accessor) MethodsThese methods DO NOT modify the Object object |
|
Methods of the Object class, all of which are inherited by every object via prototype . | |
hasOwnProperty() | Returns a boolean indicating whether the object has the specified direct property. |
isPrototypeOf() | Returns a boolean indicating whether the object exists in another objects hierarchy. |
toLocaleString() | Returns a string representation of an object. |
toString() | Returns a string representation of an object. |
valueOf() | Returns the primitive value of the specified object. |
Setter (Mutator) MethodsThese methods DO modify the Object object |
|
None. |
Examples
The code below creates an object with some properties.
/*
Create an object that holds first and last name properties
*/
var homeOwner = new Object();
homeOwner.firstName = 'Teddy';
homeOwner.lastName = 'Bear';
alert(homeOwner.firstName + ' ' + homeOwner.lastName);
/*
We could just as easily assign the surname property with a typo as below
and then scratched our heads when we tried to access the nameStore.lastName
property. Be careful what you type when assigning object properties
*/
homeOwner.lastNaem = Bear;
Related Tutorials
JavaScript Basic Tutorials - Lesson 7 - Objects