HTML and CSS Reference
In-Depth Information
Objects
JavaScript also supports objects; in fact, most values in JavaScript applications will be ob-
jects. JavaScript also supports syntax for defining classes that objects can be instantiated
from. This may lead you to think JavaScript is a conventional object orientated language -
this would be a mistake.
In classical object orientated languages such as Java and C#, classes must be defined before
objects can be instantiated from them. It is never possible to have an object that is not a type
of a specific class.
Classes are static templates that contain definitions of the properties and methods that ob-
jects will contain. During program execution, instances of these classes are created: these
are called objects. All objects instantiated from the same class have the same properties and
methods, although the values assigned to properties will differ from instance to instance.
When designing applications with a classical object orientated language you may find cases
where you would like some objects to contain additional properties or methods, even though
they are similar in other respects those created by an existing class. For instance you may
have started with a class called “Vehicle” which contained the following properties:
1. Registration number
2. Initial year of registration
3. Make of vehicle
4. Model of vehicle
Objects can be instantiated from this class, and will contain four properties to which values
can be assigned.
//
This topic will use the term “property” to refer to the state of an object. Other lan-
guages may call these fields or attributes.
You may subsequently decide that you would like to capture more information about trucks,
for instance:
1. Number of axles
2. Towing capacity
Search WWH ::




Custom Search