HTML and CSS Reference
In-Depth Information
verbs are called methods in object-oriented languages. JavaScript sees your browser
window as an object, a window that can be resized, opened, closed, and so on. It sees all
the frames, documents, images, and widgets inside the window as objects. And these
objects have properties and methods.
JavaScript supports several types of objects, as follows:
1. User-defined objects defined by the programmer.
2. Core or built-in objects, such as Date, String, and Number (see Chapter 9,
“JavaScript Core Objects”).
3. Browser objects, the BOM (see Chapter 10, “It's the BOM! Browser Objects”).
4. The Document objects, the DOM (see Chapter 15, “The W3C DOM and Java-
Script”).
This chapter focuses on user-defined objects, objects that you will create and manipu-
late. Once you understand the syntax and how these objects work, JavaScript's core
objects will be much easier to understand and use.
8.1.1 Objects and the Dot Syntax
An object model is a hierarchical tree-like structure used to describe all of the compo-
nents of an object (see Figure 8.1). For example, in Chapter 1, “Introduction to Java-
Script,” we discussed the DOM (see more in Chapter 15), a tree-like structure that
represents an HTML document and all of its elements, and this tree-like model is also
used to represent the browser and its components (BOM; see Chapter 10). JavaScript
objects and user-defined objects use this same model. When accessing an object in the
tree, the object at the top of the tree is the root or parent of all parents. If there is an
object below the parent it is called the child, and if the object is on the same level, it is
a sibling. A child can also have children. A dot (.) is used to separate the objects when
descending the tree; for example, a parent is separated from its child with a dot. In the
following example, the Object object is the primitive JavaScript object from which all
other objects are derived and the Object object has its own properties and methods that
all objects will have access to. (We list these properties and methods in Tables 8.1 and
8.2.) The cat object and the dog object are derived from the Object object . To get the cat's
name, you would say cat.name, and to get the dog's breed you would say dog.breed . The
Object object is not named when going down in the hierarchy.
Object
Cat
Dog
name
color
size
attitude
name
color
breed
Figure 8.1 A hierarchical tree-like structure used to describe components of an object.
 
 
Search WWH ::




Custom Search