Java

Submitted by: Submitted by

Views: 217

Words: 3361

Pages: 14

Category: Science and Technology

Date Submitted: 07/14/2012 12:38 PM

Report This Essay

JavaSc ript — An O bject-

Based L anguage

In this chapter, you look at a concept that is central to JavaScript, namely objects. But what are objects, and why are they useful?

First, we have to break it to you: You have been using objects throughout this book (for example, an array is an object). JavaScript is an object-based language, and therefore most of what you do involves manipulating objects. You’ll see that when you make full use of these objects, the range of things you can do with JavaScript expands immensely.

We’ll start this chapter by taking a look at the idea of what objects are and why they are important. We’ll move on to what kinds of objects are used in JavaScript, how to create them and use them, and how they simplify many programming tasks for you. Finally, you’ll see in more detail some of the most useful objects that JavaScript provides and how to use these in practical situations.

Not only does the JavaScript language consist of a number of these things called objects (which are also called native JavaScript objects), but also the browser itself is modeled as a collection of objects available for your use. You’ll learn about these objects in particular in the next chapter.

Object- Based Programming

Object-based programming is a slightly scarier way of saying “programming using objects.” But what are these objects that you will be programming with? Where are they and how and why would you want to program with them? In this section, you’ll look at the answers to these questions, both in general programming terms and more specifically within JavaScript.

Chapter 5: JavaScript — An Object-Based Language

What Are Objects?

To start the introduction to objects, let’s think about what is meant by an object in the “real world” outside computing. The world is composed of things, or objects, such as tables, chairs, and cars (to name just a few!). Let’s take a car as an example, to explore what an object really is.

How would you define the car?...