HTML and CSS Reference
In-Depth Information
8.1 What Are Objects?
JavaScript is all about objects. Windows and buttons, forms and images, links and
anchors are all objects. Programming languages like Java, C++, and Python that focus
on objects are called object-oriented programming (OOP) languages. JavaScript is called
an object-based language because it doesn't technically meet the criteria of the more
heavy-duty languages, but it certainly behaves as an object-oriented language. Some
people are apprehensive at the thought of tackling this kind of programming, although
the mystique is somewhat diminished from what it was back in the last century when
the top-down procedural approach to programming was more in vogue. In the real
world, you may see a book or a cup or a hat as an object. JavaScript can represent data
such as a string or a number as an object, and JavaScript lets you create your own
objects. When talking about JavaScript data types in Chapter 3, “The Building Blocks:
Data Types, Literals, and Variables,” we discussed two types: primitive and composite.
Objects are composite types. They provide a way to organize a collection of data into a
single unit. Object-oriented languages, such as C++ and Java, bundle up data and behav-
ior and call it an object. So does JavaScript.
When you learn about objects, they are usually compared to real-world things, like a
cat, a book, or a triangle. Using the English language to describe an object, the object
itself would be like a noun.
Nouns are described with adjectives. A cat might be described as fat, furry, smart, or
lazy. The topic is old, with 400 pages, and contains poems. The triangle has three sides,
three angles, and red lines. The adjectives that collectively describe these objects are
called properties or attributes . The object is made up of a collection of these properties
or attributes.
In English, verbs are used to describe what the object can do or what can be done to
it. The cat eats, sleeps, and meows. The topic is read, its pages can be turned forward
and backward, and it can be opened or closed by the reader. The triangle's sides and
angles can be increased and decreased, it can be moved, and it can be colored. These
Search WWH ::

Custom Search