Changes

Jump to: navigation, search

JavaScript Object Basics

9 bytes added, 13:42, 20 June 2007
Creating and Using Object Instances
== Creating and Using Object Instances ==
In the previous section we learned how to create an object definition. It is important to note that, at this point, we have only described what the object will do (we have bascically created blueprint of the object), we have not actually created an object we can work with (this is known as an ''object instance''). Object instances are created using the ''new'' keywrod and are assigned to an object variable that will be used to reference the object. For example, in the following example we will create anew a new instance of the car object with the name myCar:
<pre>
We have also passed through parameters to initialize the properties of the object (make, model and color).
Next we need to understand how to call a method on an object and access an object property. This is achieved by using what is called dot noation notation on the name of the object instance:
To access a property:
</pre>
In our example we have a method called displayCar() to display the 3 properties of the object. Follwoing Following the above dot notation syntax we can call this method as follows:
<pre>

Navigation menu