JavaScript is an object-based language. The term object-based should not make you nervous: For us, object-based programming will be a lot easier. For our purposes, object-based programming just means that JavaScript makes available objects that give us access to some aspect of the browser or document. For example, we already have used the document object, one of the most powerful JavaScript objects, in this chapter. That object refers to the body of the Web page in the browser. With this object, you have access to the HTML in the page. In the previous example, I used the writeln (which stands for "write line") method of the document object to write "Welcome to JavaScript!" , like this: <SCRIPT LANGUAGE="JavaScript"> <!-- document.writeln("Welcome to JavaScript!") //--> </SCRIPT> You can use methods such as writeln to have an object perform some action, such as writing to the Web page. Other methods let you force the browser to navigate to a new page, send data back to scripts on the server, and so on. The objects that you already have access to in JavaScript give you a great deal of power. For example, we'll use the document object to access XML documents in the next chapter. Here's an overview of some of the most popular JavaScript objects and what they're all about:
Many more objects exist in JavaScript, and you can define your own objectssee the JavaScript documentation for the details. When you want to create your own objects, you first define a class, which you can consider the type of the object. Using the JavaScript new operator, you can create objects from classes; we won't create classes here, but we'll use the new operator later in this chapter to create objects in the next chapter. You have to know about two aspects of objects to be able to get anywhere methods, which we've already seen, and properties. |