Professional JavaScript for Web Developers

( 2 )

Overview

This book provides a developer-level introduction along with more advanced and useful features of JavaScript. Coverage includes:

  • JavaScript use with HTML to create dynamic webpages, language concepts including syntax and flow control ...
See more details below
Paperback
$26.76
BN.com price
(Save 40%)$44.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (16) from $22.68   
  • New (12) from $24.56   
  • Used (4) from $22.67   
Professional JavaScript for Web Developers

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$25.99
BN.com price
(Save 42%)$44.99 List Price

Overview

This book provides a developer-level introduction along with more advanced and useful features of JavaScript. Coverage includes:

  • JavaScript use with HTML to create dynamic webpages, language concepts including syntax and flow control statements
  • variable handling given their loosely typed nature
  • built-in reference types such as object and array
  • object-oriented programing
  • powerful aspects of function expressions
  • Browser Object Model allowing interaction with the browser itself
  • detecting the client and its capabilities
  • Document Object Model (DOM) objects available in DOM Level 1
  • how DOM Levels 2 and 3 augmented the DOM
  • events, legacy support, and how the DOM redefined how events should work
  • enhancing form interactions and working around browser limitations
  • using the <canvas> tag to create on-the-fly graphics
  • JavaScript API changes in HTML5
  • how browsers handle JavaScript errors and error handling
  • features of JavaScript used to read and manipulate XML data
  • the JSON data format as an alternative to XML
  • Ajax techniques including the use of XMLHttpRequest object and CORS
  • complex patterns including function currying, partial function application, and dynamic functions
  • offline detection and storing data on the client machine
  • techniques for JavaScript in an enterprise environment for better maintainability

This book is aimed at three groups of readers: Experienced object-oriented programming developers looking to learn JavaScript as it relates to traditional OO languages such as Java and C++; Web application developers attempting to enhance site usability; novice JavaScript developers.

Nicholas C. Zakas worked with the Web for over a decade. He has worked on corporate intranet applications used by some of the largest companies in the world and large-scale consumer websites such as MyYahoo! and the Yahoo! homepage. He regularly gives talks at companies and conferences regarding front-end best practices and new technology.

Read More Show Less

Product Details

  • ISBN-13: 9781118026694
  • Publisher: Wiley
  • Publication date: 1/18/2012
  • Edition number: 3
  • Pages: 960
  • Sales rank: 110,357
  • Product dimensions: 7.40 (w) x 9.20 (h) x 1.80 (d)

Meet the Author

Nicholas C. Zakas is a front-end architect who honed his skills working at Yahoo! for five years. He has worked in web development for over a decade, developing web solutions for some of the largest companies in the world. He is the author of previous editions of Professional JavaScript for Web Developers and a coauthor of Professional Ajax.

Read More Show Less

Read an Excerpt

Professional JavaScript for Web Developers


By Nicholas C. Zakas

John Wiley & Sons

Copyright © 2012 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-1-1180-2669-4


Chapter One

What Is JavaScript?

WHAT'S IN THIS CHAPTER?

* Review of JavaScript history

* What JavaScript is

* How JavaScript and ECMAScript are related

* The different versions of JavaScript

When JavaScript first appeared in 1995, its main purpose was to handle some of the input validation that had previously been left to server-side languages such as Perl. Prior to that time, a round-trip to the server was needed to determine if a required field had been left blank or an entered value was invalid. Netscape Navigator sought to change that with the introduction of JavaScript. The capability to handle some basic validation on the client was an exciting new feature at a time when use of telephone modems was widespread. The associated slow speeds turned every trip to the server into an exercise in patience.

Since that time, JavaScript has grown into an important feature of every major web browser on the market. No longer bound to simple data validation, JavaScript now interacts with nearly all aspects of the browser window and its contents. JavaScript is recognized as a full programming language, capable of complex calculations and interactions, including closures, anonymous (lambda) functions, and even metaprogramming. JavaScript has become such an important part of the Web that even alternative browsers, including those on mobile phones and those designed for users with disabilities, support it. Even Microsoft, with its own client-side scripting language called VBScript, ended up including its own JavaScript implementation in Internet Explorer from its earliest version.

The rise of JavaScript from a simple input validator to a powerful programming language could not have been predicted. JavaScript is at once a very simple and very complicated language that takes minutes to learn but years to master. To begin down the path to using JavaScript's full potential, it is important to understand its nature, history, and limitations.

A SHORT HISTORY

As the Web gained popularity, a gradual demand for client-side scripting languages developed. At the time, most Internet users were connecting over a 28.8 kbps modem even though web pages were growing in size and complexity. Adding to users' pain was the large number of round-trips to the server required for simple form validation. Imagine filling out a form, clicking the Submit button, waiting 30 seconds for processing, and then being met with a message indicating that you forgot to complete a required field. Netscape, at that time on the cutting edge of technological innovation, began seriously considering the development of a client-side scripting language to handle simple processing.

Brendan Eich, who worked for Netscape at the time, began developing a scripting language called Mocha, and later LiveScript, for the release of Netscape Navigator 2 in 1995, with the intention of using it both in the browser and on the server (where it was to be called LiveWire). Netscape entered into a development alliance with Sun Microsystems to complete the implementation of LiveScript in time for release. Just before Netscape Navigator 2 was officially released, Netscape changed LiveScript's name to JavaScript to capitalize on the buzz that Java was receiving from the press.

Because JavaScript 1.0 was such a hit, Netscape released version 1.1 in Netscape Navigator 3. The popularity of the fledgling Web was reaching new heights, and Netscape had positioned itself to be the leading company in the market. At this time, Microsoft decided to put more resources into a competing browser named Internet Explorer. Shortly after Netscape Navigator 3 was released, Microsoft introduced Internet Explorer 3 with a JavaScript implementation called JScript (so called to avoid any possible licensing issues with Netscape). This major step for Microsoft into the realm of web browsers in August 1996 is now a date that lives in infamy for Netscape, but it also represented a major step forward in the development of JavaScript as a language.

Microsoft's implementation of JavaScript meant that there were two different JavaScript versions floating around: JavaScript in Netscape Navigator and JScript in Internet Explorer. Unlike C and many other programming languages, JavaScript had no standards governing its syntax or features, and the three different versions only highlighted this problem. With industry fears mounting, it was decided that the language must be standardized.

In 1997, JavaScript 1.1 was submitted to the European Computer Manufacturers Association (Ecma) as a proposal. Technical Committee #39 (TC39) was assigned to "standardize the syntax and semantics of a general purpose, cross-platform, vendor-neutral scripting language" (www.ecma-international.org/memento/TC39.htm). Made up of programmers from Netscape, Sun, Microsoft, Borland, NOMBAS, and other companies with interest in the future of scripting, TC39 met for months to hammer out ECMA-262, a standard defining a new scripting language named ECMAScript (often pronounced as "ek-ma-script").

The following year, the International Organization for Standardization and International Electrotechnical Commission (ISO/IEC) also adopted ECMAScript as a standard (ISO/IEC-16262). Since that time, browsers have tried, with varying degrees of success, to use ECMAScript as a basis for their JavaScript implementations.

JAVASCRIPT IMPLEMENTATIONS

Though JavaScript and ECMAScript are often used synonymously, JavaScript is much more than just what is defined in ECMA-262. Indeed, a complete JavaScript implementation is made up of the following three distinct parts (see Figure 1-1):

* The Core (ECMAScript)

* The Document Object Model (DOM)

* The Browser Object Model (BOM)

ECMAScript

ECMAScript, the language defined in ECMA-262, isn't tied to web browsers. In fact, the language has no methods for input or output whatsoever. ECMA-262 defines this language as a base upon which more-robust scripting languages may be built. Web browsers are just one host environment in which an ECMAScript implementation may exist. A host environment provides the base implementation of ECMAScript and implementation extensions designed to interface with the environment itself. Extensions, such as the Document Object Model (DOM), use ECMAScript's core types and syntax to provide additional functionality that's more specific to the environment. Other host environments include NodeJS, a server-side JavaScript platform, and Adobe Flash.

What exactly does ECMA-262 specify if it doesn't reference web browsers? On a very basic level, it describes the following parts of the language:

* Syntax

* Types

* Statements

* Keywords

* Reserved words

* Operators

* Objects

ECMAScript is simply a description of a language implementing all of the facets described in the specification. JavaScript implements ECMAScript, but so does Adobe ActionScript.

ECMAScript Editions

The different versions of ECMAScript are defined as editions (referring to the edition of ECMA-262 in which that particular implementation is described). The most recent edition of ECMA-262 is edition 5, released in 2009. The first edition of ECMA-262 was essentially the same as Netscape's JavaScript 1.1 but with all references to browser-specific code removed and a few minor changes: ECMA-262 required support for the Unicode standard (to support multiple languages) and that objects be platform-independent (Netscape JavaScript 1.1 actually had different implementations of objects, such as the Date object, depending on the platform). This was a major reason why JavaScript 1.1 and 1.2 did not conform to the first edition of ECMA-262.

The second edition of ECMA-262 was largely editorial. The standard was updated to get into strict agreement with ISO/IEC-16262 and didn't feature any additions, changes, or omissions. ECMAScript implementations typically don't use the second edition as a measure of conformance.

The third edition of ECMA-262 was the first real update to the standard. It provided updates to string handling, the definition of errors, and numeric outputs. It also added support for regular expressions, new control statements, try-catch exception handling, and small changes to better prepare the standard for internationalization. To many, this marked the arrival of ECMAScript as a true programming language.

The fourth edition of ECMA-262 was a complete overhaul of the language. In response to the popularity of JavaScript on the Web, developers began revising ECMAScript to meet the growing demands of web development around the world. In response, Ecma TC39 reconvened to decide the future of the language. The resulting specification defined an almost completely new language based on the third edition. The fourth edition includes strongly typed variables, new statements and data structures, true classes and classical inheritance, and new ways to interact with data.

As an alternate proposal, a specification called "ECMAScript 3.1," was developed as a smaller evolution of the language by a subcommittee of TC39, who believed that the fourth edition was too big of a jump for the language. The result was a smaller proposal with incremental changes to ECMAScript that could be implemented on top of existing JavaScript engines. Ultimately, the ES3.1 subcommittee won over support from TC39, and the fourth edition of ECMA-262 was abandoned before officially being published.

ECMAScript 3.1 became ECMA-262, fifth edition, and was officially published on December 3, 2009. The fifth edition sought to clarify perceived ambiguities of the third edition and introduce additional functionality. The new functionality includes a native JSON object for parsing and serializing JSON data, methods for inheritance and advanced property definition, and the inclusion of a new strict mode that slightly augments how ECMAScript engines interpret and execute code.

What Does ECMAScript Conformance Mean?

ECMA-262 lays out the definition of ECMAScript conformance. To be considered an implementation of ECMAScript, an implementation must do the following:

* Support all "types, values, objects, properties, functions, and program syntax and semantics" (ECMA-262, p. 1) as they are described in ECMA-262.

* Support the Unicode character standard.

Additionally, a conforming implementation may do the following:

* Add "additional types, values, objects, properties, and functions" that are not specified in ECMA-262. ECMA-262 describes these additions as primarily new objects or new properties of objects not given in the specification.

* Support "program and regular expression syntax" that is not defined in ECMA-262 (meaning that the built-in regular-expression support is allowed to be altered and extended).

These criteria give implementation developers a great amount of power and flexibility for developing new languages based on ECMAScript, which partly accounts for its popularity.

ECMAScript Support in Web Browsers

Netscape Navigator 3 shipped with JavaScript 1.1 in 1996. That same JavaScript 1.1 specification was then submitted to Ecma as a proposal for the new standard, ECMA-262. With JavaScript's explosive popularity, Netscape was very happy to start developing version 1.2. There was, however, one problem: Ecma hadn't yet accepted Netscape's proposal.

A little after Netscape Navigator 3 was released, Microsoft introduced Internet Explorer 3. This version of IE shipped with JScript 1.0, which was supposed to be equivalent to JavaScript 1.1. However, because of undocumented and improperly replicated features, JScript 1.0 fell far short of JavaScript 1.1.

Netscape Navigator 4 was shipped in 1997 with JavaScript 1.2 before the first edition of ECMA-262 was accepted and standardized later that year. As a result, JavaScript 1.2 is not compliant with the first edition of ECMAScript even though ECMAScript was supposed to be based on JavaScript 1.1.

The next update to JScript occurred in Internet Explorer 4 with JScript version 3.0 (version 2.0 was released in Microsoft Internet Information Server version 3.0 but was never included in a browser). Microsoft put out a press release touting JScript 3.0 as the first truly Ecma-compliant scripting language in the world. At that time, ECMA-262 hadn't yet been finalized, so JScript 3.0 suffered the same fate as JavaScript 1.2: it did not comply with the final ECMAScript standard.

Netscape opted to update its JavaScript implementation in Netscape Navigator 4.06 to JavaScript 1.3, which brought Netscape into full compliance with the first edition of ECMA-262. Netscape added support for the Unicode standard and made all objects platform-independent while keeping the features that were introduced in JavaScript 1.2.

When Netscape released its source code to the public as the Mozilla project, it was anticipated that JavaScript 1.4 would be shipped with Netscape Navigator 5. However, a radical decision to completely redesign the Netscape code from the bottom up derailed that effort. JavaScript 1.4 was released only as a server-side language for Netscape Enterprise Server and never made it into a web browser.

By 2008, the five major web browsers (Internet Explorer, Firefox, Safari, Chrome, and Opera) all complied with the third edition of ECMA-262. Internet Explorer 8 was the first to start implementing the fifth edition of ECMA-262 specification and delivered complete support in Internet Explorer 9. Firefox 4 soon followed suit. The following table lists ECMAScript support in the most popular web browsers.

The Document Object Model (DOM)

The Document Object Model (DOM) is an application programming interface (API) for XML that was extended for use in HTML. The DOM maps out an entire page as a hierarchy of nodes. Each part of an HTML or XML page is a type of a node containing different kinds of data. Consider the following HTML page:

Hello World!

This code can be diagrammed into a hierarchy of nodes using the DOM (see Figure 1-2).

By creating a tree to represent a document, the DOM allows developers an unprecedented level of control over its content and structure. Nodes can be removed, added, replaced, and modified easily by using the DOM API.

Why the DOM Is Necessary

With Internet Explorer 4 and Netscape Navigator 4 each supporting different forms of Dynamic HTML (DHTML), developers for the first time could alter the appearance and content of a web page without reloading it. This represented a tremendous step forward in web technology but also a huge problem. Netscape and Microsoft went separate ways in developing DHTML, thus ending the period when developers could write a single HTML page that could be accessed by any web browser.

It was decided that something had to be done to preserve the cross-platform nature of the Web. The fear was that if someone didn't rein in Netscape and Microsoft, the Web would develop into two distinct factions that were exclusive to targeted browsers. It was then that the World Wide Web Consortium (W3C), the body charged with creating standards for web communication, began working on the DOM.

DOM Levels

DOM Level 1 became a W3C recommendation in October 1998. It consisted of two modules: the DOM Core, which provided a way to map the structure of an XML-based document to allow for easy access to and manipulation of any part of a document, and the DOM HTML, which extended the DOM Core by adding HTML-specific objects and methods.

Note that the DOM is not JavaScript-specifi c and indeed has been implemented in numerous other languages. For web browsers, however, the DOM has been implemented using ECMAScript and now makes up a large part of the JavaScript language.

Whereas the goal of DOM Level 1 was to map out the structure of a document, the aims of DOM Level 2 were much broader. This extension of the original DOM added support for mouse and user-interface events (long supported by DHTML), ranges, traversals (methods to iterate over a DOM document), and support for Cascading Style Sheets (CSS) through object interfaces. The original DOM Core introduced in Level 1 was also extended to include support for XML namespaces. DOM Level 2 introduced the following new modules of the DOM to deal with new types of interfaces:

* DOM Views—Describes interfaces to keep track of the various views of a document (the document before and after CSS styling, for example)

* DOM Events—Describes interfaces for events and event handling

* DOM Style—Describes interfaces to deal with CSS-based styling of elements

* DOM Traversal and Range—Describes interfaces to traverse and manipulate a document tree

(Continues...)



Excerpted from Professional JavaScript for Web Developers by Nicholas C. Zakas Copyright © 2012 by John Wiley & Sons, Ltd. Excerpted by permission of John Wiley & Sons. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents

FOREWORD xxxi

INTRODUCTION xxxiii

CHAPTER 1: WHAT IS JAVASCRIPT? 1

CHAPTER 2: JAVASCRIPT IN HTML 13

CHAPTER 3: LANGUAGE BASICS 25

CHAPTER 4: VARIABLES, SCOPE, AND MEMORY 85

CHAPTER 5: REFERENCE TYPES 103

CHAPTER 6: OBJECT-ORIENTED PROGRAMMING 173

CHAPTER 7: FUNCTION EXPRESSIONS 217

CHAPTER 8: THE BROWSER OBJECT MODEL 239

CHAPTER 9: CLIENT DETECTION 271

CHAPTER 10: THE DOCUMENT OBJECT MODEL 309

CHAPTER 11: DOM EXTENSIONS 357

CHAPTER 12: DOM LEVELS 2 AND 3 381

CHAPTER 13: EVENTS 431

CHAPTER 14: SCRIPTING FORMS 511

CHAPTER 15: GRAPHICS WITH CANVAS 551

CHAPTER 16: HTML5 SCRIPTING 591

CHAPTER 17: ERROR HANDLING AND DEBUGGING 607

CHAPTER 18: XML IN JAVASCRIPT 641

CHAPTER 19: ECMASCRIPT FOR XML 671

CHAPTER 20: JSON 691

CHAPTER 21: AJAX AND COMET 701

CHAPTER 22: ADVANCED TECHNIQUES 731

CHAPTER 23: OFFLINE APPLICATIONS AND CLIENT-SIDE STORAGE 765

CHAPTER 24: BEST PRACTICES 801

CHAPTER 25: EMERGING APIS 835

APPENDIX A: ECMASCRIPT HARMONY 857

APPENDIX B: STRICT MODE 877

APPENDIX C: JAVASCRIPT LIBRARIES 885

APPENDIX D: JAVASCRIPT TOOLS 891

INDEX 897

Read More Show Less

Customer Reviews

Average Rating 4.5
( 2 )
Rating Distribution

5 Star

(1)

4 Star

(1)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 4 Customer Reviews
  • Anonymous

    Posted January 20, 2014

    This is an excellent book. No question 5 stars. However, it is v

    This is an excellent book. No question 5 stars. However, it is very dense and chapters 4-8, which repeats some information in slightly different contexts, could confuse some beginners as it did me, not a beginner. But it you take your time, read slowly and thoughtfully, and re-read these chapters a of couple times, the information will start to sink in and it will start to make some sense why some information in chapters 4-8 was presented in the way it was.

    One thing I particularly like about the book is that the author likes to use ECMAScript as the starting reference point for discussions. By using a single starting reference point throughout the book, and by initially comparing Browser implementations against ECMAScript, instead of immediately comparing Browser implementations against one another, the topics are presented in a far more logical/organized fashion for the brain to comprehend than they would be otherwise, and the book is well positioned not only for logically comparing Browser implementations against one another, but for comparing Browser implementations against the ideal, ECMAScript, which not only gives the book an air of authority, but makes it an excellent reference. In other words, the book does not teach the language through the differences in Browser implementations. Rather, it first teaches the language through the standards, and then it teaches Browser implementations; first, by comparison to the standards, and then by comparison to other Browsers. This, I thought, was excellent idea, and it was well done. Chapters 10-21 are good at this.

    My only complaints about the book are that the index is weak (I started keeping one myself), and that the book's binding broke and the pages are falling out.

    Steve

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 19, 2013

    Recommended - A good reference book

    Explains ECMAscript, DOM, & BOM in detail.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 20, 2005

    Typos Suggest No-one Proofread

    Multiple instances of 'toLocalString' instead of 'toLocaleString,' often within the same sentence, make the book appear slapdash.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 22, 2005

    Great JavaScript Book

    This is the best JavaScript book that I've come across. Zakas' expertise is clearly demonstrated through his explanations and code samples. This book is now my go to book when I need a refresher.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 4 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)