Objects

First, let’s think about objects. An object is some kind of a thing. A cat, a computer, and a bicycle are all objects (Figure 1.5) in the physical world. To JavaScript, there are objects it deals with in Web browsers, such as windows and forms, and the elements of the form, such as buttons and check boxes (Figure 1.6).

Figure 1.5. The cat object (this one’s name is Pixel).


Figure 1.6. The buttons and check box are browser objects, which can be manipulated by JavaScript.


Because you can have more than one cat, or more than one window, it makes sense to give them names. While you could refer to your pets as Cat #1 and Cat #2, it’s a bad idea for two reasons: first, it’s easier to tell the cats apart if they have unique names, and second, it’s just plain impolite. In the same way, all the examples in this book will give objects their own unique names.

✓ Tips

  • Be aware that scripts you might see on the Internet will refer to objects like window[0] and form[1]. This is poor style for the reasons given above, and you’ll find that it’s much easier for you to keep track of the different objects in your scripts if you give them names instead of numbers.

  • Some persnickety programmers will argue that JavaScript isn’t really object-oriented, but rather, that it’s actually object-based. For the purposes of this book, the two meanings are close enough that it makes no difference.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.95.216