After the fourth edition of JavaScript: The Definitive Guide was published, the Document Object Modelthe fundamental API for client-side JavaScript™ programmingbecame widely, if not completely, implemented in web browsers. This meant that web developers had a stable, mature language (JavaScript 1.5) and a common API for manipulating web pages on the client. Several years of stability followed. But things have started to get interesting again. Developers are now using JavaScript to script HTTP, manipulate XML data, and even draw dynamic graphics in a web browser. Many JavaScript developers have also started to write longer programs and use more sophisticated programming techniques, such as closures and namespaces. This fifth edition has been fully revised for the new world of Ajax and Web 2.0 technologies. What's New in the Fifth EditionIn Part I, Core JavaScript, the chapter on functions (Chapter 8) has been expanded, with particular emphasis on nested functions and closures. The material on defining your own classes has also been expanded and moved to a chapter of its own (Chapter 9). Chapter 10 is another new chapter that covers namespaces, which are essential for writing modular, reusable code. Finally, Chapter 12 demonstrates how to use JavaScript to actually script Java; it shows how to embed a JavaScript interpreter within a Java 6 application and how to use JavaScript to create Java objects and invoke methods on those objects. In Part II, Client-Side JavaScript, the coverage of the legacy (Level 0) Document Object Model has been merged with the coverage of the W3C standard DOM. Because the DOM is now universally implemented, there is no need for two separate chapters on manipulating documents. The biggest change in Part II, however, is the amount of new material:
Part III, the reference section for the core JavaScript API, is little changed from the previous edition, because that API has remained stable. If you have used the fourth edition, you'll find this part of the book comfortingly familiar. The big change to the reference material is that the documentation of the DOM API, which was previously segregated into a section of its own, has been fully integrated into Part IV, the client-side JavaScript reference section. Now there is only one client-side reference section to consult. No more looking up the Document object in one reference section and then looking up the HTMLDocument object in the other. Reference material for DOM interfaces that were never (widely) implemented in web browsers has simply been cut. The NodeIterator interface, for example, is simply not available in web browsers, and it no longer clutters up this book. The focus has also been moved away from the awkwardly formal interfaces defined by the DOM specification and onto the JavaScript objects that actually implement those interfaces. So, for example, getComputedStyle( ) is now documented as a method of the Window object, where you'd expect it, rather than as a method of the AbstractView interface. There is no reason that client-side JavaScript programmers should care about AbstractView, and it has simply been removed from the reference. All these changes result in a simpler, easier-to-use client-side reference section. Using This BookChapter 1 provides an introduction to JavaScript. The rest of the book is in four parts. Part I, which immediately follows this chapter, documents the core JavaScript language. Chapters 2 through 6 cover some bland but necessary reading; these chapters cover the basic information you need to understand when learning a new programming language:
The next six chapters of Part I become more interesting. They still cover the core of the JavaScript language, but they document parts of the language that will not be familiar to you even if you already know C or Java. These chapters must be studied carefully if you want to really understand JavaScript:
Part II explains JavaScript in web browsers. The first six chapters cover the core features of client-side JavaScript:
These first six chapters of Part II are followed by five more that cover advanced topics in client-side JavaScript.
Parts III and IV contain reference material covering core JavaScript and client-side JavaScript, respectively. These parts document relevant objects, methods, and properties alphabetically. Conventions Used in This BookThe following formatting conventions are used in this book:
Using Code ExamplesThis book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "JavaScript: The Definitive Guide, by David Flanagan. Copyright 2006 O'Reilly Media, Inc., 978-0-596-10199-2." If you feel your use of code examples falls outside fair use of the permission given above, feel free to contact us at permissions@oreilly.com. Safari® EnabledWhen you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf. Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com. How to Contact UsPlease address comments and questions concerning this book to the publisher:
We have a web page for this book that lists errata, examples, or any additional information. You can access this page at: http://www.oreilly.com/catalog/jscript5 You can also download the examples from the author's web site: http://www.davidflanagan.com/javascript5 To comment or ask technical questions about this book, send email to: bookquestions@oreilly.com For more information about our books, conferences, Resource Centers, and the O'Reilly Network, see our web site at: http://www.oreilly.com/ AcknowledgmentsBrendan Eich of the Mozilla organization is the originator and chief innovator of JavaScript. I, and many JavaScript developers, owe Brendan a tremendous debt of gratitude for developing JavaScript and for taking the time out of his crazy schedule to answer our questions and even solicit our input. Besides patiently answering my many questions, Brendan also read and provided very helpful comments on the first and third editions of this book. This book has been blessed with top-notch technical reviewers whose comments have gone a long way toward making it a stronger and more accurate book. Aristotle Pagaltzis (http://plasmasturm.org) reviewed the new material on functions and the new chapters on classes and namespaces in this edition. He gave my code a particularly careful review and had many useful comments. Douglas Crockford (http://www.crockford.com) reviewed the new material on functions and classes. Norris Boyd, creator of the Rhino JavaScript interpreter, reviewed the chapter on embedding JavaScript in Java applications. Peter-Paul Koch (http://www.quirksmode.org), Christian Heilmann (http://www.wait-till-i.com), and Ken Cooper reviewed the Ajax-related chapters of the book. Ken was kind enough to pitch in at the end and help out with new client-side reference material. Todd Ditchendorf (http://www.ditchnet.org) and Geoff Stearns (http://blog.deconcept.com) reviewed the chapter on scripted client-side graphics. Todd was kind enough to find and isolate a bug for me, and Geoff helped me understand Flash and ActionScript. Finally, Sanders Kleinfeld reviewed the entire book with remarkable attention to detail. His suggestions and technical corrections have make the book clearer and more precise. My sincere thanks to each of them for their careful reviews. Any errors that remain are, of course, my own. I am also grateful to the reviewers of the fourth edition. Waldemar Horwat at Netscape reviewed the new material on JavaScript 1.5. The new material on the W3C DOM was reviewed by Philippe Le Hegaret of the W3C and by Peter-Paul Koch, Dylan Schiemann, and Jeff Yates. Although he was not a reviewer, Joseph Kesselman of IBM Research was very helpful in answering my questions about the W3C DOM. The third edition of the book was reviewed by Brendan Eich, Waldemar Horwat, and Vidur Apparao at Netscape; Herman Venter at Microsoft; and two independent JavaScript developers, Jay Hodges and Angelo Sirigos. Dan Shafer did some preliminary work on the third edition. Although his material was not used in this edition, his ideas and general outline were quite helpful. Norris Boyd and Scott Furman at Netscape also provided useful information for this edition, and Vidur Apparao of Netscape and Scott Issacs of Microsoft each took the time to talk to me about the forthcoming Document Object Model standard. Finally, Dr. Tankred Hirschmann provided challenging insights into the intricacies of JavaScript 1.2. The second edition benefited greatly from the help and comments of Nick Thompson and Richard Yaker of Netscape; Dr. Shon Katzenberger, Larry Sullivan, and Dave C. Mitchell at Microsoft; and Lynn Rollins of R&B Communications. The first edition was reviewed by Neil Berkman of Bay Networks and by Andrew Schulman and Terry Allen of O'Reilly. This book also gains strength from the diversity of editors it has had. Deb Cameron is the editor of this edition and has given the book a thorough edit and much-needed freshening, with special emphasis on removing outdated material. Paula Ferguson edited the third and fourth editions. Frank Willison edited the second edition, and Andrew Schulman edited the first. Finally, my thanks, as always and for so many reasons, to Christie.
|