CHAPTER 1 ■ A BRIEF HISTORY OF JAVASCRIPT
2
■ Note JavaScript has nothing to do with Java, a programming language developed by Sun Microsystems.
JavaScript was originally going to be called LiveScript. JavaScript was probably chosen to make the new language
sound like it was in good company. Unfortunately, the choice of this name had the effect of confusing the two
languages in people’s minds—a confusion that was amplified by the fact that web browsers also supported a form
of client-side Java. However, while Java’s strength lies in the fact that it can theoretically be deployed in almost
any environment, JavaScript was always intended for the confines of the web browser.
JavaScript is a scripting language. Unlike a program that does everything itself, the JavaScript
language simply tells the web browser what to do. The web browser interprets the script and does all the
work, which is why JavaScript is often compared unfavorably with compiled programming languages
like Java and C++. But JavaScript’s relative simplicity is also its strength. Because it has a low barrier to
entry, nonprogrammers who wanted to cut and paste scripts into their existing web pages quickly
adopted the language.
JavaScript also offers developers the chance to manipulate aspects of the web browser. For example,
the language could be used to adjust the properties of a browser window, such as its height, width, and
position. Addressing the browser’s own properties in this way can be thought of as a Browser Object
Model. Early versions of JavaScript also provided a primitive sort of DOM.
The Document Object Model
What is the DOM? In short, the DOM is a way of conceptualizing the contents of a document.
In the real world, we all share something that could be called a World Object Model. We can refer to
objects in our environment using terms like car, house, and tree, and be fairly certain that our terms will
be understood. That’s because we have mutually agreed on which objects the words refer to specifically.
If you say “The car is in the garage,” it’s safe to assume that the person you’re talking to won’t take that
to mean “The bird is in the cupboard.”
Our World Object Model isn’t restricted to tangible objects though; it also applies to concepts. For
instance, you might refer to “the third house on the left” when giving directions. For that description to
make sense, the concepts of “third” and “left” must be understood. If you give that description to
someone who can’t count, or who can’t tell left from right, then the description is essentially
meaningless, whether or not the words have been understood. In reality, because people agree on a
conceptual World Object Model, very brief descriptions can be full of meaning. You can be fairly sure
that others share your concepts of left and third.
It’s the same situation with web pages. Early versions of JavaScript offered developers the ability to
query and manipulate some of the actual contents of web documents—mostly images and forms.
Because the terms images and forms had been predefined, JavaScript could be used to address the third
image in the document or the form named details, as follows:
document.images[2]
document.forms['details']
This first, tentative sort of DOM is often referred to as DOM Level 0. In those early, carefree days, the
most common usage of DOM Level 0 was for image rollovers and some client-side form validation. But
when the fourth generation of browsers from Netscape and Microsoft appeared, the DOM really hit the
fan.