Table of Contents
About the Author
Alexei White is a programmer, designer, and speaker. He is the inventor of RobotReplay, a web session-tracking technology acquired by Foresee Results, and an author of the book Enterprise Ajax, as well as the DVD training series Enterprise Ajax LiveLessons. He has contributed to major Web projects for Microsoft and Nintendo. His blog can be found at http://ambiguiti.es . When hes not working in Vancouver he can be found floating on a lake somewhere in the interior of British Columbia with a fishing pole in his hand. You may also find him on Twitter (@alexsaves).
Credits
Acquisitions Editor
Scott Meyers
Development Editor
Ed Connor
Technical Editor
Alexei Gorkov
Production Editor
Daniel Scribner
Copy Editor
Christopher Jones
Editorial Director
Robyn B. Siesky
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Lynsey Stanford
Proofreader
Publication Services, Inc.
Indexer
Ron Strauss
Acknowledgments
A book like this is never written in a vacuum, and there are many people who played an important role in getting it done, and contributing to the overall quality. I want to thank some people in the development community for their overall contributions to JavaScript over the years, and helping to advance the understanding and skills of a large community of developers. This group certainly includes Douglas Crockford, John Resig, Dustin Diaz, Valerio Proietti, Alex Russel, Eric Lawrence (thank you for Fiddler), Joe Hewitt (of Firebug fame - and who should have schools named after him or something), and of course many more.
Thanks also go to Nitobi, Foresee Results, Adobe, the Mozilla Foundation, Opera Software, Microsoft, and Apple either for making my life a lot easier, or for their continuing contributions to the web development community (keep making great tools!)
On a personal note, I want to thank my fianc Lara for never being anything but totally supportive whether I am working late, writing all weekend, or generally not doing any of my chores as a result. I also want to thank my parents for giving me everything I ever needed to succeed.
Introduction
Since its introduction by Netscape over fourteen years ago, JavaScript has become one of the most widely used scripting languages in existence. Today, virtually every personal computer on the planet has a JavaScript engine on it, whether its a Mac, Windows PC, or Linux computer. It helps developers create rich user experiences on the web, and is a contributing factor to the development of the Internet as a viable platform for business applications.
This book is intended to be more than a simple collection of tutorials and reference material. Its meant to be a comprehensive and accurate resource for both new and experienced developers. Its the kind of book youll want to keep next to your computer at all times to flip through to remind yourself of techniques, browser compatibility, and in-depth explanation on some of the most bleeding-edge features of the language. It moves from the basics of syntax, general characteristics, and flow-control, to advanced approaches to object oriented inheritance, offline storage, Ajax, and debugging. Still, you dont need to read this book from cover-to-cover. It uses discrete examples instead of large reference applications, and clear meaningful headings for easy browsing. You can jump to any point in the material, and provided you have at least some understanding of the preceding chapters, you should be able to jump right in. Finally, this book differs from other JavaScript books by pushing you beyond casual familiarity, and by providing some new tools to solve difficult real-world problems.
Who This Book Is For
Given that there are many varied implementations of ECMAScript both in and outside the browser, its necessary to clarify who will benefit most from this reference. This book is intended for developers pursuing primarily client-side browser-based JavaScript development, although many of the concepts also apply to server-side and compiled implementations using, for example, Rhino, Spidermonkey, or JScript.NET.
The early chapters in this book provide a thorough introduction to all the language fundamentals, so no previous JavaScript experience is required. Some other prior programming experience is helpful since much of the terminology and syntax will be the same as with other languages. Experienced JavaScript developers will also get a great deal out of the middle and end portions of the book as well as the reference material in the appendices.
Some prior experience with HTML is also desirable as I wont be explaining the meaning of different HTML tags or explaining the basic structure of HTML documents in any depth.
This book is also an ideal resource for designers wishing to expand their understanding of browser scripting. If you come from a design background and already understand CSS and HTML, you will be well prepared for the sections on DHTML, animation, and Cascading Style Sheets.
Most of all, Ive designed this book to be the go-to resource for all serious JavaScript developers, and the kind of book youll want to keep next to your computer all the times. As you advance in your abilities, and your applications become more sophisticated, youll find new gems between these pages to keep you coming back.
How This Book Is Structured
The chapters in this book are designed to be incremental with the more elementary subjects covered in the first four chapters, intermediate topics between five and fifteen, and advanced topics near the end. Its incremental in the sense that beginners should start at Chapter 1 and read straight through, but the entire book has been structured to be of use to developers at all skill levels. Even in the early chapters, advanced developers will appreciate the inclusion of some fairly low-level information on the language, performance, and compatibility.
Here is a brief description of each chapter to assist you.
Chapter 1: Introduction to JavaScript provides an overview of the language today as well as a brief history of its evolution from its early beginnings around the days of Netscape 2. This chapter explains the role of various related technologies like CSS, and the DOM. It also introduces the reader to a representative Hello World JavaScript application.
Chapter 2: JavaScript in the Browser gives a detailed overview of how exactly JavaScript fits into the browser runtime, how we include script on a page, and control the execution by way of browser events.
Chapter 3: JavaScript Basics explains the fundamental characteristics of JavaScript and how it compares to other programming languages at a low level. Other topics covered here include variables, garbage collection, type conversion and objects.