Table Of Content01_579088 ffirs.qxd 3/28/05 11:33 AM Page ii
01_579088 ffirs.qxd 3/28/05 11:33 AM Page i
Professional JavaScript™ for Web Developers
01_579088 ffirs.qxd 3/28/05 11:33 AM Page ii
01_579088 ffirs.qxd 3/28/05 11:33 AM Page iii
Professional JavaScript™ for Web Developers
Nicholas C. Zakas
01_579088 ffirs.qxd 3/28/05 11:33 AM Page iv
Professional JavaScript™ for Web Developers
Copyright © 2005 by Wiley Publishing Inc. All rights reserved.
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as
permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior
written permission of the Publisher, or authorization through payment of the appropriate per-copy fee
to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax
(978) 646-8700. Requests to the Publisher for permission should be addressed to the Legal Department,
Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317)
572-4355, or online at www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR
MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR
COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL
WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR APARTIC-
ULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMO-
TIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR EVERYSITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT
THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PRO-
FESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A
COMPETENT PROFESSIONALPERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOT
THE AUTHOR SHALLBE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN
ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS ACITATION AND/OR A
POTENTIALSOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR
THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY
PROVIDE OR RECOMMENDATIONS IT MAYMAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAYHAVE CHANGED OR DISAPPEARED
BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Depart-
ment within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317)
572-4002.
Trademarks:Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, and Programmer to Programmer
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates. JavaScript is a
trademark of Sun Microsystems, Inc. in the United States and other countries. All other trademarks are
the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or
vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data is available from the publisher.
ISBN-13: 978-0-7645-7908-0
ISBN-10: 0-7645-7908-8
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1
01_579088 ffirs.qxd 3/28/05 11:33 AM Page v
About the Author
Nicholas C. Zakasis a user interface designer for Web applications, specializing in client-side technolo-
gies such as JavaScript, HTML, and CSS. Nicholas currently works as Senior Software Engineer, Design
Engineering, at MatrixOne, Inc. located in Westford, Massachusetts, USA.
Nicholas has a B.S. in Computer Science from Merrimack College, where he learned traditional pro-
gramming in C and C++. During college, he began investigating the World Wide Web and HTMLin his
spare time, eventually teaching himself enough to be hired as Webmaster of a small software company
named Radnet, Inc. in Wakefield, Massachusetts, USA. It was there that Nicholas began learning
JavaScript and working on Web applications.
Nicholas can be reached through his Web site, http://www.nczonline.net/.
01_579088 ffirs.qxd 3/28/05 11:33 AM Page vi
Credits
Vice President and Executive Group Publisher: Development Editor:
Richard Swadley Sharon Nash
Vice President and Publisher: Senior Production Editor:
Joseph B. Wikert Angela Smith
Acquisitions Editor: Technical Editor:
Jim Minatel Jean-Luc David, Wiley-Dreamtech India Pvt Ltd
Editorial Manager: Text Design & Composition:
Mary Beth Wakefield Wiley Composition Services
01_579088 ffirs.qxd 3/28/05 11:33 AM Page vii
Acknowledgments
It takes more than just one person to write a book of this nature, despite the single name on the front
cover. Without the help of numerous individuals, this book would not have been possible.
First are foremost, thanks to everyone at Wiley Publishing, especially Jim Minatel and Sharon Nash, for
providing all the guidance and support that a new author needs.
Thanks to all those who offered their ideas on what a good JavaScript book should include: Keith
Ciociola, Ken Fearnley, John Rajan, and Douglas Swatski.
Aspecial thanks to everyone who reviewed the subject matter ahead of time: Erik Arvidsson, Bradley
Baumann, Guilherme Blanco, Douglas Crockford, Jean-Luc David, Emil A. Eklund, Brett Fielder, Jeremy
McPeak, and Micha Schopman. All your input was excellent and made for a much better book.
Thanks to Drs. Ed and Frances Bernard for keeping me in tip-top health during the writing of this book
and the past few years.
Last, but certainly not least, thanks to my family, mom, dad, and Greg, and my extremely understanding
girlfriend, Emily. Your love and support helped take me from the proposal to the final published copy.
vii
01_579088 ffirs.qxd 3/28/05 11:33 AM Page viii
Description:* Dispels the myth that JavaScript is a "baby" language and demonstrates why it is the scripting language of choice used in the design of millions of Web pages and server-side applications * Quickly covers JavaScript basics and then moves on to more advanced topics such as object-oriented programmin