Member operators
JS Home <<
JS Reference <<
Member
Access members of an object.
Description
Member operators allow access to the properties and methods of an object.
- Under the hood properties and methods are the same thing. A method is a property with a function for it's value.
- We can use dot or bracket notation to access the members of an object.
Dot Notation
The first way of accessing the members of an object is through dot notation.
Syntax
| Signature | Description |
|---|---|
anObject.property | Get an object property. |
anObject.property = setProperty | Set an object property. |
Parameters
| Parameter | Description |
|---|---|
property | A valid JavaScript identifier.
|
Examples
Lets see some examples of using dot notation.
// Store properties in an array.
var dotProps = new Array(6);
dotProps[0] = Object.prototype + '\n';
dotProps[1] = Object.constructor + '\n';
dotProps[2] = Math.E + '\n';
dotProps[3] = Math.PI + '\n';
dotProps[4] = Object.toString() + '\n';
dotProps[5] = Date.parse();
alert(dotProps);
Press the button below to action the above code:
Bracket Notation
The second way of accessing the members of an object is through bracket notation.
Syntax
| Signature | Description |
|---|---|
anObject[property] | Get an object property. |
anObject[property] = setProperty | Set an object property. |
Parameters
| Parameter | Description |
|---|---|
property | A string that isn't constrained by the naming limitations of dot notation.
|
Examples
Lets see some examples of using bracket notation.
// Store properties in an array.
var bracketProps = new Array(6);
bracketProps[0] = Object['prototype'] + '\n';
bracketProps[1] = Object['constructor'] + '\n';
bracketProps[2] = Math['E'] + '\n';
bracketProps[3] = Math['PI'] + '\n';
bracketProps[4] = Object['toString'] + '\n';
bracketProps[5] = Date['parse'];
alert(bracketProps);
Press the button below to action the above code:
Related Tutorials
JavaScript Basic Tutorials - Lesson 7 - Objects
