Download Full Professional JavaScript for Web Developers 1st Edition Nicholas C. Zakas PDF All Chapters
Download Full Professional JavaScript for Web Developers 1st Edition Nicholas C. Zakas PDF All Chapters
com
https://ebookname.com/product/professional-javascript-for-
web-developers-1st-edition-nicholas-c-zakas/
OR CLICK BUTTON
DOWLOAD EBOOK
https://ebookname.com/product/professional-ajax-2nd-edition-
programmer-to-programmer-nicholas-c-zakas/
ebookname.com
https://ebookname.com/product/security-for-web-developers-using-
javascript-html-and-css-early-release-raw-unedited-john-paul-mueller/
ebookname.com
https://ebookname.com/product/pro-javascript-for-web-apps-1st-edition-
adam-freeman/
ebookname.com
https://ebookname.com/product/development-success-historical-accounts-
from-more-advanced-countries-1st-edition-augustin-k-fosu/
ebookname.com
Nietzsche on mind and nature 1st Edition Dries
https://ebookname.com/product/nietzsche-on-mind-and-nature-1st-
edition-dries/
ebookname.com
https://ebookname.com/product/canada-and-the-united-states-
differences-that-count-fifth-edition-david-thomas/
ebookname.com
https://ebookname.com/product/neurobiology-of-personality-
disorders-1st-edition-christian-schmahl-editor/
ebookname.com
https://ebookname.com/product/humanities-world-report-2015-1st-
edition-poul-holm/
ebookname.com
Nicholas C. Zakas
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, MA 01923, (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.
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
About the Author
Nicholas C. Zakas is 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 HTML in 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.
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.
A special 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
Contents
Acknowledgments vii
Introduction xxi
ix
Contents
The String class 29
The instanceof operator 32
Operators 33
Unary operators 33
Bitwise operators 37
Boolean operators 43
Multiplicative operators 46
Additive operators 47
Relational operators 49
Equality operators 50
Conditional operator 52
Assignment operators 52
Comma operator 53
Statements 53
The if statement 53
Iterative statements 54
Labeled statements 56
The break and continue statements 56
The with statement 58
The switch statement 58
Functions 59
No overloading 61
The arguments object 62
The Function class 63
Closures 65
Summary 66
x
Contents
Scope 88
Public, protected, and private 88
Static is not static 88
The this keyword 89
Defining Classes and Objects 90
Factory paradigm 90
Constructor paradigm 92
Prototype paradigm 93
Hybrid constructor/prototype paradigm 94
Dynamic prototype method 95
Hybrid factory paradigm 96
Which one to use? 97
A practical example 97
Modifying Objects 99
Creating a new method 99
Redefining an existing method 100
Very late binding 101
Summary 102
xi
Contents
JavaScript in SVG 133
Basic SVG 133
The <script/> tag in SVG 134
Tag placement in SVG 135
The Browser Object Model 136
The window object 136
The document object 149
The location object 153
The navigator object 155
The screen object 156
Summary 157
xii
Contents
Simple Patterns 197
Metacharacters 197
Using special characters 197
Character classes 199
Quantifiers 201
Complex Patterns 205
Grouping 205
Backreferences 206
Alternation 207
Non-capturing groups 209
Lookaheads 210
Boundaries 210
Multiline mode 212
Understanding the RegExp Object 212
Instance properties 213
Static properties 214
Common Patterns 216
Validating dates 216
Validating credit cards 218
Validating e-mail addresses 222
Summary 223
xiii
Contents
Detecting Konqueror/Safari 239
Detecting Internet Explorer 241
Detecting Mozilla 242
Detecting Netscape Communicator 4.x 243
The Platform/Operating System Detection Script 244
Methodology 244
First steps 245
Detecting Windows operating systems 245
Detecting Macintosh operating systems 247
Detecting Unix operating systems 248
The Full Script 249
Example: A Login Page 252
Summary 259
xiv
Contents
xv
Contents
Moving Options 361
Reordering options 361
Creating an Autosuggest Text Box 362
Matching 362
The guts 363
Summary 365
xvi
Contents
xvii
Contents
Chapter 16: Client-Server Communication 481
Cookies 481
Cookie ingredients 482
Other security restrictions 482
Cookies in JavaScript 483
Cookies on the server 485
Passing cookies between client and server 488
Hidden Frames 490
Using iframes 491
HTTP Requests 493
Using headers 495
Copycat implementations 496
Performing a GET request 496
Performing a POST request 497
LiveConnect Requests 498
Performing a GET request 498
Performing a POST request 500
Intelligent HTTP Requests 502
The get() method 502
The post() method 505
Practical Uses 506
Summary 507
xviii
Contents
xix
Contents
Intellectual Property Issues 593
Obfuscating 593
Microsoft Script Encoder (IE only) 594
Summary 595
Index 617
xx
Introduction
Although once supported by Netscape Enterprise Server and Active Server Pages (ASP) on the server,
JavaScript is primarily a client-side scripting language for use in Web browsers. Its main focus today is
to help developers interact with Web pages and the Web browser window itself.
JavaScript is very loosely based on Java, an object-oriented programming language popularized for use
on the Web by way of embedded applets. Although JavaScript has a similar syntax and programming
methodology, it is not a “light” version of Java. Instead, JavaScript is its own language, finding its home
in Web browsers around the world and enabling enhanced user interaction on Web sites and Web appli-
cations alike.
In this book, JavaScript is covered from its very beginning in the earliest Netscape browsers to the
present-day incarnations flush with support for XML and Web Services. You learn how to extend the
language to suit specific needs and how to create seamless client-server communication without inter-
mediaries such as Java or hidden frames. In short, you learn how to apply JavaScript solutions to
business problems faced by Web developers everywhere.
Starting at the beginning, the book explores how JavaScript originated and evolved into what it is today.
A detailed discussion of the components that make up a JavaScript implementation follows, with spe-
cific focus on standards such as ECMAScript and the Document Object Model (DOM). The differences in
JavaScript implementations used in different popular Web browsers are also discussed.
Building on that base, the book moves on to cover basic concepts of JavaScript including its version of
object-oriented programming, inheritance, and its use in various markup languages such as HTML. An
in-depth examination of events and event handling is followed by an exploration of browser detection
techniques and a guide to using regular expressions in JavaScript. The book then takes all this knowl-
edge and applies it to creating dynamic user interfaces.
The last part of the book is focused on issues related to the deployment of JavaScript solutions in Web
applications. These topics include error handling, debugging, security, optimization/obfuscation, XML,
and Web Services.
xxi
Introduction
❑ Experienced developers familiar with object-oriented programming who are looking to learn
JavaScript as it relates to traditional OO languages such as Java and C++.
❑ Web application developers attempting to enhance the usability of their Web sites and Web
applications.
❑ Novice JavaScript developers aiming to better understand the language.
In addition, familiarity with the following related technologies is a strong indicator that this book is
for you:
❑ XML
❑ XSLT
❑ Java
❑ Web Services
❑ HTML
❑ CSS
This book is not aimed at beginners lacking a basic computer science background or those looking to
add some simple user interactions to Web sites. These readers should instead refer to Wrox’s Beginning
JavaScript, Second Edition (Wiley Publishing, Inc., ISBN 0-7645-5587-1).
The complete source code for the samples is available for download from the Web site at
http://www.wrox.com/.
xxii
Introduction
2. ECMAScript Basics
This chapter examines the core technology upon which JavaScript is built, ECMAScript. This
chapter describes the basic syntax and concepts necessary to write JavaScript code, from declar-
ing variables and functions to using and understanding primitive and reference values.
3. Object Basics
This chapter focuses on the foundations of object-oriented programming (OOP) in JavaScript.
Topics covered include defining custom objects using a variety of different methods, creating
object instances, and understanding the similarities and differences to OOP in JavaScript and Java.
4. Inheritance
This chapter continues the exploration of OOP in JavaScript, describing how inheritance works.
The various methods of achieving inheritance are discussed, and these methods are compared
and contrasted with inheritance in Java.
6. DOM Basics
This chapter introduces the DOM as implemented in JavaScript. It includes an introduction to
DOM concepts of specific value to Web developers. These concepts are applied later in exam-
ples using HTML, SVG, and XUL.
7. Regular Expressions
This chapter focuses on the JavaScript implementation of regular expressions, which are a pow-
erful tool for data validation and string manipulation. The origins of regular expressions are
explored, as well as its syntax and usage across a variety of programming languages. The chap-
ter ends with an explanation of the similarities and differences in JavaScript’s implementation.
xxiii
Discovering Diverse Content Through
Random Scribd Documents
CAPITULO XIX.
Execútase la prision de Motezuma: dáse noticia del modo como
se dispuso, y como se recibió entre sus vasallos.
"Que aquel alojamiento que les habia señalado era otro palacio
suyo, donde solia residir algunas veces: y que no se podria
extrañar entré sus vasallos que se mudáse á él para deshacerse
de una culpa, que, puesta en su cabeza, sería pleyto de Rey á
Rey; y quedando en la de su General, se podria emendar con el
castigo, sin pasar á los inconvenientes y violencias con que
suele decidirse la justicia de los Reyes."
LIBRO IV.
CAPITULO PRIMERO.
Permitese á Motezuma que se dexe ver en público, saliendo á
sus templos y recreaciones. Trata Cortés de algunas
prevenciones que tuvo por necesarias; y se duda que intentasen
los Españoles en esta sazon derribar los ídolos de México.
"Que aquel era de los casos en que se debia usar primero del
entendimiento que de las manos: y que le dexáse obrar segun
la experiencia y conocimiento que tenia de aquellos humores y
de sus causas."
Portóse despues con gran reserva entre sus ministros, despreciando
el delito para descuidar al delinqüente; á cuyo fin les decia:
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com