Professional, JavaScript® for Web Developers, Second Edition

Book description

This eagerly anticipated update to the breakout book on JavaScript offers you an in-depth look at the numerous advances to the techniques and technology of the JavaScript language. You'll see why JavaScript's popularity continues to grow while you delve through topics such as debugging tools in Microsoft Visual Studio, FireBug, and Drosera; client-side data storage with cookies, DOM storage, and client-side databases; HTML 5, ECMAScript 3.1, the Selectors API; and design patterns including creational, structural, and behavorial patterns.

Table of contents

  1. Copyright
  2. About the Author
  3. Credits
  4. Acknowledgments
  5. Foreword
  6. Introduction
    1. 0.1. What Does This Book Cover?
    2. 0.2. Who Is This Book For?
    3. 0.3. What You Need to Use This Book
    4. 0.4. How This Book Is Structured
    5. 0.5. Conventions
    6. 0.6. Source Code
    7. 0.7. Errata
    8. 0.8. p2p.wrox.com
  7. 1. What Is JavaScript?
    1. 1.1. A Short History
    2. 1.2. JavaScript Implementations
      1. 1.2.1. ECMAScript
        1. 1.2.1.1. ECMAScript Editions
        2. 1.2.1.2. What Does ECMAScript Conformance Mean?
        3. 1.2.1.3. ECMAScript Support in Web Browsers
      2. 1.2.2. The Document Object Model (DOM)
        1. 1.2.2.1. Why the DOM Is Necessary
        2. 1.2.2.2. DOM Levels
        3. 1.2.2.3. Other DOMs
        4. 1.2.2.4. DOM Support in Web Browsers
      3. 1.2.3. The Browser Object Model (BOM)
    3. 1.3. JavaScript Versions
    4. 1.4. Summary
  8. 2. JavaScript in HTML
    1. 2.1. The <script> Element
      1. 2.1.1. Tag Placement
      2. 2.1.2. Deferred Scripts
      3. 2.1.3. Changes in XHTML
      4. 2.1.4. Deprecated Syntax
      5. 2.1.5. Inline Code versus External Files
    2. 2.2. Document Modes
    3. 2.3. The <noscript> Element
    4. 2.4. Summary
  9. 3. Language Basics
    1. 3.1. Syntax
      1. 3.1.1. Case-sensitivity
      2. 3.1.2. Identifiers
      3. 3.1.3. Comments
      4. 3.1.4. Statements
    2. 3.2. Keywords and Reserved Words
    3. 3.3. Variables
    4. 3.4. Data Types
      1. 3.4.1. The typeof Operator
      2. 3.4.2. The Undefined Type
      3. 3.4.3. The Null Type
      4. 3.4.4. The Boolean Type
      5. 3.4.5. The Number Type
        1. 3.4.5.1. Floating-Point Values
        2. 3.4.5.2. Range of Values
        3. 3.4.5.3. NaN
        4. 3.4.5.4. Number Conversions
      6. 3.4.6. The String Type
        1. 3.4.6.1. Character Literals
        2. 3.4.6.2. The Nature of Strings
        3. 3.4.6.3. Converting to a String
      7. 3.4.7. The Object Type
    5. 3.5. Operators
      1. 3.5.1. Unary Operators
        1. 3.5.1.1. Increment/Decrement
        2. 3.5.1.2. Unary Plus and Minus
      2. 3.5.2. Bitwise Operators
        1. 3.5.2.1. Bitwise NOT
        2. 3.5.2.2. Bitwise AND
        3. 3.5.2.3. Bitwise OR
        4. 3.5.2.4. Bitwise XOR
        5. 3.5.2.5. Left Shift
        6. 3.5.2.6. Signed Right Shift
        7. 3.5.2.7. Unsigned Right Shift
      3. 3.5.3. Boolean Operators
        1. 3.5.3.1. Logical NOT
        2. 3.5.3.2. Logical AND
        3. 3.5.3.3. Logical OR
      4. 3.5.4. Multiplicative Operators
        1. 3.5.4.1. Multiply
        2. 3.5.4.2. Divide
        3. 3.5.4.3. Modulus
      5. 3.5.5. Additive Operators
        1. 3.5.5.1. Add
        2. 3.5.5.2. Subtract
      6. 3.5.6. Relational Operators
      7. 3.5.7. Equality Operators
        1. 3.5.7.1. Equal and Not Equal
        2. 3.5.7.2. Identically Equal and Not Identically Equal
      8. 3.5.8. Conditional Operator
      9. 3.5.9. Assignment Operators
      10. 3.5.10. Comma Operator
    6. 3.6. Statements
      1. 3.6.1. The if Statement
      2. 3.6.2. The do-while Statement
      3. 3.6.3. The while Statement
      4. 3.6.4. The for Statement
      5. 3.6.5. The for-in Statement
      6. 3.6.6. Labeled Statements
      7. 3.6.7. The break and continue Statements
      8. 3.6.8. The with Statement
      9. 3.6.9. The switch Statement
    7. 3.7. Functions
      1. 3.7.1. Understanding Arguments
      2. 3.7.2. No Overloading
    8. 3.8. Summary
  10. 4. Variables, Scope, and Memory
    1. 4.1. Primitive and Reference Values
      1. 4.1.1. Dynamic Properties
      2. 4.1.2. Copying Values
      3. 4.1.3. Argument Passing
      4. 4.1.4. Determining Type
    2. 4.2. Execution Context and Scope
      1. 4.2.1. Scope Chain Augmentation
      2. 4.2.2. No Block-Level Scopes
        1. 4.2.2.1. Variable Declaration
        2. 4.2.2.2. Identifier Lookup
    3. 4.3. Garbage Collection
      1. 4.3.1. Mark-and-Sweep
      2. 4.3.2. Reference Counting
      3. 4.3.3. Performance
      4. 4.3.4. Managing Memory
    4. 4.4. Summary
  11. 5. Reference Types
    1. 5.1. The Object Type
    2. 5.2. The Array Type
      1. 5.2.1. Conversion Methods
      2. 5.2.2. Stack Methods
      3. 5.2.3. Queue Methods
      4. 5.2.4. Reordering Methods
      5. 5.2.5. Manipulation Methods
    3. 5.3. The Date Type
      1. 5.3.1. Inherited Methods
      2. 5.3.2. Date-Formatting Methods
      3. 5.3.3. Date/Time Component Methods
    4. 5.4. The RegExp Type
      1. 5.4.1. RegExp Instance Properties
      2. 5.4.2. RegExp Instance Methods
      3. 5.4.3. RegExp Constructor Properties
      4. 5.4.4. Pattern Limitations
    5. 5.5. The Function Type
      1. 5.5.1. No Overloading (Revisited)
      2. 5.5.2. Function Declarations vs. Function Expressions
      3. 5.5.3. Functions as Values
      4. 5.5.4. Function Internals
      5. 5.5.5. Function Properties and Methods
    6. 5.6. Primitive Wrapper Types
      1. 5.6.1. The Boolean Type
      2. 5.6.2. The Number Type
      3. 5.6.3. The String Type
        1. 5.6.3.1. Character Methods
        2. 5.6.3.2. String-Manipulation Methods
        3. 5.6.3.3. String Location Methods
        4. 5.6.3.4. String Case Methods
        5. 5.6.3.5. String Pattern-Matching Methods
        6. 5.6.3.6. The localeCompare() Method
        7. 5.6.3.7. The fromCharCode() Method
        8. 5.6.3.8. HTML Methods
    7. 5.7. Built-in Objects
      1. 5.7.1. The Global Object
        1. 5.7.1.1. URI-Encoding Methods
        2. 5.7.1.2. The eval() Method
        3. 5.7.1.3. Global Object Properties
        4. 5.7.1.4. The Window Object
      2. 5.7.2. The Math Object
        1. 5.7.2.1. Math Object Properties
        2. 5.7.2.2. The min() and max() Methods
        3. 5.7.2.3. Rounding Methods
        4. 5.7.2.4. The random() Method
        5. 5.7.2.5. Other Methods
    8. 5.8. Summary
  12. 6. Object-Oriented Programming
    1. 6.1. Creating Objects
      1. 6.1.1. The Factory Pattern
      2. 6.1.2. The Constructor Pattern
        1. 6.1.2.1. Constructors as Functions
        2. 6.1.2.2. Problems with Constructors
      3. 6.1.3. The Prototype Pattern
        1. 6.1.3.1. How Prototypes Work
        2. 6.1.3.2. Prototypes and the in Operator
        3. 6.1.3.3. Alternate Prototype Syntax
        4. 6.1.3.4. Dynamic Nature of Prototypes
        5. 6.1.3.5. Native Object Prototypes
        6. 6.1.3.6. Problems with Prototypes
      4. 6.1.4. Combination Constructor/Prototype Pattern
      5. 6.1.5. Dynamic Prototype Pattern
      6. 6.1.6. Parasitic Constructor Pattern
      7. 6.1.7. Durable Constructor Pattern
    2. 6.2. Inheritance
      1. 6.2.1. Prototype Chaining
        1. 6.2.1.1. Default Prototypes
        2. 6.2.1.2. Prototype and Instance Relationships
        3. 6.2.1.3. Working with Methods
        4. 6.2.1.4. Problems with Prototype Chaining
      2. 6.2.2. Constructor Stealing
        1. 6.2.2.1. Passing Arguments
        2. 6.2.2.2. Problems with Constructor Stealing
      3. 6.2.3. Combination Inheritance
      4. 6.2.4. Prototypal Inheritance
      5. 6.2.5. Parasitic Inheritance
      6. 6.2.6. Parasitic Combination Inheritance
    3. 6.3. Summary
  13. 7. Anonymous Functions
    1. 7.1. Recursion
    2. 7.2. Closures
      1. 7.2.1. Closures and Variables
      2. 7.2.2. The this Object
      3. 7.2.3. Memory Leaks
    3. 7.3. Mimicking Block Scope
    4. 7.4. Private Variables
      1. 7.4.1. Static Private Variables
      2. 7.4.2. The Module Pattern
      3. 7.4.3. The Module-Augmentation Pattern
    5. 7.5. Summary
  14. 8. The Browser Object Model
    1. 8.1. The window Object
      1. 8.1.1. The Global Scope
      2. 8.1.2. Window Relationships and Frames
      3. 8.1.3. Window Position
      4. 8.1.4. Window Size
      5. 8.1.5. Navigating and Opening Windows
        1. 8.1.5.1. Popping Up Windows
        2. 8.1.5.2. Security Restrictions
        3. 8.1.5.3. Pop-up Blockers
      6. 8.1.6. Intervals and Timeouts
      7. 8.1.7. System Dialogs
    2. 8.2. The location Object
      1. 8.2.1. Query String Arguments
      2. 8.2.2. Manipulating the Location
    3. 8.3. The navigator Object
      1. 8.3.1. Detecting Plug-ins
      2. 8.3.2. Registering Handlers
    4. 8.4. The screen Object
    5. 8.5. The history Object
    6. 8.6. Summary
  15. 9. Client Detection
    1. 9.1. Capability Detection
    2. 9.2. Quirks Detection
    3. 9.3. User-Agent Detection
      1. 9.3.1. History
        1. 9.3.1.1. Early Browsers
        2. 9.3.1.2. Netscape Navigator 3 and Internet Explorer 3
        3. 9.3.1.3. Netscape Communicator 4 and Internet Explorer 4–8
        4. 9.3.1.4. Gecko
        5. 9.3.1.5. WebKit
        6. 9.3.1.6. Konqueror
        7. 9.3.1.7. Chrome
        8. 9.3.1.8. Opera
      2. 9.3.2. Working with User-Agent Detection
        1. 9.3.2.1. Identifying the Rendering Engine
        2. 9.3.2.2. Identifying the Browser
        3. 9.3.2.3. Identifying the Platform
        4. 9.3.2.4. Identifying Windows Operating Systems
        5. 9.3.2.5. Identifying Mobile Devices
        6. 9.3.2.6. Identifying Game Systems
      3. 9.3.3. The Complete Script
      4. 9.3.4. Usage
    4. 9.4. Summary
  16. 10. The Document Object Model
    1. 10.1. Hierarchy of Nodes
      1. 10.1.1. The Node Type
        1. 10.1.1.1. The nodeName and nodeValue Properties
        2. 10.1.1.2. Node Relationships
        3. 10.1.1.3. Manipulating Nodes
        4. 10.1.1.4. Other Methods
      2. 10.1.2. The Document Type
        1. 10.1.2.1. Document Children
        2. 10.1.2.2. Document Information
        3. 10.1.2.3. Locating Elements
        4. 10.1.2.4. Special Collections
        5. 10.1.2.5. DOM Conformance Detection
        6. 10.1.2.6. Document Writing
      3. 10.1.3. The Element Type
        1. 10.1.3.1. HTML Elements
        2. 10.1.3.2. Getting Attributes
        3. 10.1.3.3. Setting Attributes
        4. 10.1.3.4. The attributes Property
        5. 10.1.3.5. Creating Elements
        6. 10.1.3.6. Element Children
      4. 10.1.4. The Text Type
        1. 10.1.4.1. Creating Text Nodes
        2. 10.1.4.2. Normalizing Text Nodes
        3. 10.1.4.3. Splitting Text Nodes
      5. 10.1.5. The Comment Type
      6. 10.1.6. The CDATASection Type
      7. 10.1.7. The DocumentType Type
      8. 10.1.8. The DocumentFragment Type
      9. 10.1.9. The Attr Type
    2. 10.2. DOM Extensions
      1. 10.2.1. Rendering Modes
      2. 10.2.2. Scrolling
      3. 10.2.3. The children Property
      4. 10.2.4. The contains() Method
      5. 10.2.5. Content Manipulation
        1. 10.2.5.1. The innerText Property
        2. 10.2.5.2. The innerHTML Property
        3. 10.2.5.3. The outerText Property
        4. 10.2.5.4. The outerHTML Property
        5. 10.2.5.5. Memory and Performance Issues
    3. 10.3. Working with the DOM
      1. 10.3.1. Dynamic Scripts
      2. 10.3.2. Dynamic Styles
      3. 10.3.3. Manipulating Tables
      4. 10.3.4. Using NodeLists
    4. 10.4. Summary
  17. 11. DOM Levels 2 and 3
    1. 11.1. DOM Changes
      1. 11.1.1. XML Namespaces
        1. 11.1.1.1. Changes to Node
        2. 11.1.1.2. Changes to Document
        3. 11.1.1.3. Changes to Element
        4. 11.1.1.4. Changes to NamedNodeMap
      2. 11.1.2. Other Changes
        1. 11.1.2.1. Changes to DocumentType
        2. 11.1.2.2. Changes to Document
        3. 11.1.2.3. Changes to Node
        4. 11.1.2.4. Changes to Frames
    2. 11.2. Styles
      1. 11.2.1. Accessing Element Styles
        1. 11.2.1.1. DOM Style Properties and Methods
        2. 11.2.1.2. Computed Styles
      2. 11.2.2. Working with Style Sheets
        1. 11.2.2.1. CSS Rules
        2. 11.2.2.2. Creating Rules
        3. 11.2.2.3. Deleting Rules
      3. 11.2.3. Element Dimensions
        1. 11.2.3.1. Offset Dimensions
        2. 11.2.3.2. Client Dimensions
        3. 11.2.3.3. Scroll Dimensions
        4. 11.2.3.4. Determining Element Dimensions
    3. 11.3. Traversals
      1. 11.3.1. NodeIterator
      2. 11.3.2. TreeWalker
    4. 11.4. Ranges
      1. 11.4.1. Ranges in the DOM
        1. 11.4.1.1. Simple Selection in DOM Ranges
        2. 11.4.1.2. Complex Selection in DOM Ranges
        3. 11.4.1.3. Interacting with DOM Range Content
        4. 11.4.1.4. Inserting DOM Range Content
        5. 11.4.1.5. Collapsing a DOM Range
        6. 11.4.1.6. Comparing DOM Ranges
        7. 11.4.1.7. Cloning DOM Ranges
        8. 11.4.1.8. Clean Up
      2. 11.4.2. Ranges in Internet Explorer
        1. 11.4.2.1. Simple Selection in IE Ranges
        2. 11.4.2.2. Complex Selection in IE Ranges
        3. 11.4.2.3. Interacting with IE Range Content
        4. 11.4.2.4. Collapsing an IE Range
        5. 11.4.2.5. Comparing IE Ranges
        6. 11.4.2.6. Cloning an IE Range
    5. 11.5. Summary
  18. 12. Events
    1. 12.1. Event Flow
      1. 12.1.1. Event Bubbling
      2. 12.1.2. Event Capturing
      3. 12.1.3. DOM Event Flow
    2. 12.2. Event Handlers or Listeners
      1. 12.2.1. HTML Event Handlers
      2. 12.2.2. DOM Level 0 Event Handlers
      3. 12.2.3. DOM Level 2 Event Handlers
      4. 12.2.4. Internet Explorer Event Handlers
      5. 12.2.5. Cross-Browser Event Handlers
    3. 12.3. The Event Object
      1. 12.3.1. The DOM Event Object
      2. 12.3.2. The Internet Explorer Event Object
      3. 12.3.3. Cross-Browser Event Object
    4. 12.4. Event Types
      1. 12.4.1. UI Events
      2. 12.4.2. Mouse Events
        1. 12.4.2.1. Client Coordinates
        2. 12.4.2.2. Screen Coordinates
        3. 12.4.2.3. Modifier Keys
        4. 12.4.2.4. Related Elements
        5. 12.4.2.5. Buttons
        6. 12.4.2.6. Additional Event Information
        7. 12.4.2.7. Mobile Safari Support
        8. 12.4.2.8. Accessibility Issues
      3. 12.4.3. Keyboard Events
        1. 12.4.3.1. Key Codes
        2. 12.4.3.2. Character Codes
        3. 12.4.3.3. The textInput Event
        4. 12.4.3.4. Keyboard Events on Devices
      4. 12.4.4. HTML Events
        1. 12.4.4.1. The load Event
        2. 12.4.4.2. The unload Event
        3. 12.4.4.3. The resize Event
        4. 12.4.4.4. The scroll Event
      5. 12.4.5. Mutation Events
        1. 12.4.5.1. Node Removal
        2. 12.4.5.2. Node Insertion
        3. 12.4.5.3. Attribute Changes
        4. 12.4.5.4. Text Changes
      6. 12.4.6. Proprietary Events
        1. 12.4.6.1. The contextmenu Event
        2. 12.4.6.2. The beforeunload Event
        3. 12.4.6.3. The Mousewheel and DOMMouseScroll Events
        4. 12.4.6.4. The DOMContentLoaded Event
        5. 12.4.6.5. The readystatechange Event
        6. 12.4.6.6. The pageshow and pagehide Events
      7. 12.4.7. Mobile Safari Events
        1. 12.4.7.1. The orientationchange Event
        2. 12.4.7.2. Touch Events
        3. 12.4.7.3. Gesture Events
    5. 12.5. Memory and Performance
      1. 12.5.1. Event Delegation
      2. 12.5.2. Removing Event Handlers
    6. 12.6. Simulating Events
      1. 12.6.1. DOM Event Simulation
        1. 12.6.1.1. Simulating Mouse Events
        2. 12.6.1.2. Simulating Keyboard Events
        3. 12.6.1.3. Simulating Other Events
      2. 12.6.2. Internet Explorer Event Simulation
    7. 12.7. Summary
  19. 13. Scripting Forms
    1. 13.1. Form Basics
      1. 13.1.1. Submitting Forms
      2. 13.1.2. Resetting Forms
      3. 13.1.3. Form Fields
        1. 13.1.3.1. Common Form-Field Properties
        2. 13.1.3.2. Common Form-Field Methods
        3. 13.1.3.3. Common Form-Field Events
    2. 13.2. Scripting Text Boxes
      1. 13.2.1. Text Selection
        1. 13.2.1.1. The select Event
        2. 13.2.1.2. Retrieving Selected Text
        3. 13.2.1.3. Partial Text Selection
      2. 13.2.2. Input Filtering
        1. 13.2.2.1. Blocking Characters
        2. 13.2.2.2. Dealing with the Clipboard
      3. 13.2.3. Automatic Tab Forward
    3. 13.3. Scripting Select Boxes
      1. 13.3.1. Options Selection
      2. 13.3.2. Adding Options
      3. 13.3.3. Removing Options
      4. 13.3.4. Moving and Reordering Options
    4. 13.4. Form Serialization
    5. 13.5. Rich Text Editing
      1. 13.5.1. Interacting with Rich Text
      2. 13.5.2. Rich Text Selections
      3. 13.5.3. Rich Text in Forms
    6. 13.6. Summary
  20. 14. Error Handling and Debugging
    1. 14.1. Browser Error Reporting
      1. 14.1.1. Internet Explorer
      2. 14.1.2. Firefox
      3. 14.1.3. Safari
      4. 14.1.4. Opera
      5. 14.1.5. Chrome
    2. 14.2. Error Handling
      1. 14.2.1. The try-catch Statement
        1. 14.2.1.1. The finally Clause
        2. 14.2.1.2. Error Types
        3. 14.2.1.3. Usage of try-catch
      2. 14.2.2. Throwing Errors
        1. 14.2.2.1. When to Throw Errors
        2. 14.2.2.2. Throwing Errors versus try-catch
      3. 14.2.3. The error Event
    3. 14.3. Error-Handling Strategies
      1. 14.3.1. Identify Where Errors Might Occur
        1. 14.3.1.1. Type Coercion Errors
        2. 14.3.1.2. Data Type Errors
        3. 14.3.1.3. Communication Errors
      2. 14.3.2. Distinguishing between Fatal and Nonfatal Errors
      3. 14.3.3. Log Errors to the Server
    4. 14.4. Debugging Techniques
      1. 14.4.1. Logging Messages to a Console
      2. 14.4.2. Logging Messages to the Page
      3. 14.4.3. Throwing Errors
    5. 14.5. Common Internet Explorer Errors
      1. 14.5.1. Operation Aborted
      2. 14.5.2. Invalid Character
      3. 14.5.3. Member Not Found
      4. 14.5.4. Unknown Runtime Error
      5. 14.5.5. Syntax Error
      6. 14.5.6. The System Cannot Locate the Resource Specified
    6. 14.6. Debugging Tools
      1. 14.6.1. Internet Explorer Debugger
        1. 14.6.1.1. Breakpoints
        2. 14.6.1.2. Stepping through Code
        3. 14.6.1.3. Watches
        4. 14.6.1.4. The Console
      2. 14.6.2. Firebug
        1. 14.6.2.1. Breakpoints
        2. 14.6.2.2. Stepping through Code
        3. 14.6.2.3. Watches
        4. 14.6.2.4. The JavaScript Console
        5. 14.6.2.5. Logging Function Calls
      3. 14.6.3. Drosera
        1. 14.6.3.1. Breakpoints
        2. 14.6.3.2. Stepping through Code
      4. 14.6.4. Opera JavaScript Debugger
        1. 14.6.4.1. Breakpoints
        2. 14.6.4.2. Stepping through Code
        3. 14.6.4.3. The Command Line Tab
      5. 14.6.5. Other Options
    7. 14.7. Summary
  21. 15. XML in JavaScript
    1. 15.1. XML DOM Support in Browsers
      1. 15.1.1. DOM Level 2 Core
      2. 15.1.2. The DOMParser Type
      3. 15.1.3. The XMLSerializer Type
      4. 15.1.4. DOM Level 3 Load and Save
        1. 15.1.4.1. Parsing XML
        2. 15.1.4.2. Other Parsing Modes
        3. 15.1.4.3. Serializing XML
      5. 15.1.5. XML in Internet Explorer
        1. 15.1.5.1. Serializing XML
        2. 15.1.5.2. Loading XML Files
      6. 15.1.6. Cross-Browser XML Processing
    2. 15.2. XPath Support in Browsers
      1. 15.2.1. DOM Level 3 XPath
        1. 15.2.1.1. Single Node Results
        2. 15.2.1.2. Simple Type Results
        3. 15.2.1.3. Default Type Results
        4. 15.2.1.4. Namespace Support
      2. 15.2.2. XPath in Internet Explorer
        1. 15.2.2.1. Namespace Support in Internet Explorer
      3. 15.2.3. Cross-Browser XPath
    3. 15.3. XSLT Support in Browsers
      1. 15.3.1. XSLT in Internet Explorer
        1. 15.3.1.1. Simple XSLT Transformations
        2. 15.3.1.2. Complex XSLT Transformations
      2. 15.3.2. The XSLTProcessor Type
        1. 15.3.2.1. Using Parameters
        2. 15.3.2.2. Resetting the Processor
      3. 15.3.3. Cross-Browser XSLT
    4. 15.4. Summary
  22. 16. ECMAScript for XML
    1. 16.1. E4X Types
      1. 16.1.1. The XML Type
      2. 16.1.2. The XMLList Type
      3. 16.1.3. The Namespace Type
      4. 16.1.4. The QName Type
    2. 16.2. General Usage
      1. 16.2.1. Accessing Attributes
      2. 16.2.2. Other Node Types
      3. 16.2.3. Querying
      4. 16.2.4. XML Construction and Manipulation
      5. 16.2.5. Parsing and Serialization Options
      6. 16.2.6. Namespaces
    3. 16.3. Other Changes
    4. 16.4. Enabling Full E4X
    5. 16.5. Summary
  23. 17. Ajax and JSON
    1. 17.1. The XHR Object
      1. 17.1.1. XHR Usage
      2. 17.1.2. HTTP Headers
      3. 17.1.3. GET Requests
      4. 17.1.4. POST Requests
      5. 17.1.5. Browser Differences
        1. 17.1.5.1. Timeouts
        2. 17.1.5.2. The load Event
        3. 17.1.5.3. The progress Event
      6. 17.1.6. Security
    2. 17.2. Cross-Domain Requests
      1. 17.2.1. The XDomainRequest Object
      2. 17.2.2. Cross-Domain XHR
    3. 17.3. JSON
      1. 17.3.1. Using JSON with Ajax
      2. 17.3.2. Security
    4. 17.4. Summary
  24. 18. Advanced Techniques
    1. 18.1. Advanced Functions
      1. 18.1.1. Scope-Safe Constructors
      2. 18.1.2. Lazy Loading Functions
      3. 18.1.3. Function Binding
      4. 18.1.4. Function Currying
    2. 18.2. Advanced Timers
      1. 18.2.1. Repeating Timers
      2. 18.2.2. Yielding Processes
      3. 18.2.3. Function Throttling
    3. 18.3. Custom Events
    4. 18.4. Drag-and-Drop
      1. 18.4.1. Fixing Drag Functionality
      2. 18.4.2. Adding Custom Events
    5. 18.5. Summary
  25. 19. Client-Side Storage
    1. 19.1. Cookies
      1. 19.1.1. Restrictions
      2. 19.1.2. Cookie Parts
      3. 19.1.3. Cookies in JavaScript
      4. 19.1.4. Subcookies
      5. 19.1.5. Cookie Considerations
    2. 19.2. Internet Explorer User Data
    3. 19.3. DOM Storage
      1. 19.3.1. The Storage Type
      2. 19.3.2. The sessionStorage Object
      3. 19.3.3. The globalStorage Object
      4. 19.3.4. The localStorage Object
      5. 19.3.5. The StorageItem Type
      6. 19.3.6. The storage Event
      7. 19.3.7. Limits and Restrictions
    4. 19.4. Summary
  26. 20. Best Practices
    1. 20.1. Maintainability
      1. 20.1.1. What Is Maintainable Code?
      2. 20.1.2. Code Conventions
        1. 20.1.2.1. Readability
        2. 20.1.2.2. Variable and Function Naming
        3. 20.1.2.3. Variable Type Transparency
      3. 20.1.3. Loose Coupling
        1. 20.1.3.1. Decouple HTML/JavaScript
        2. 20.1.3.2. Decouple CSS/JavaScript
        3. 20.1.3.3. Decouple Application Logic/Event Handlers
      4. 20.1.4. Programming Practices
        1. 20.1.4.1. Respect Object Ownership
        2. 20.1.4.2. Avoid Globals
        3. 20.1.4.3. Avoid Null Comparisons
        4. 20.1.4.4. Use Constants
    2. 20.2. Performance
      1. 20.2.1. Be Scope-Aware
        1. 20.2.1.1. Avoid Global Lookups
        2. 20.2.1.2. Avoid the with Statement
      2. 20.2.2. Choose the Right Approach
        1. 20.2.2.1. Avoid Unnecessary Property Lookup
        2. 20.2.2.2. Optimize Loops
        3. 20.2.2.3. Unrolling Loops
        4. 20.2.2.4. Avoid Double Interpretation
        5. 20.2.2.5. Other Performance Considerations
      3. 20.2.3. Minimize Statement Count
        1. 20.2.3.1. Multiple Variable Declarations
        2. 20.2.3.2. Insert Iterative Values
        3. 20.2.3.3. Use Array and Object Literals
      4. 20.2.4. Optimize DOM Interactions
        1. 20.2.4.1. Minimize Live Updates
        2. 20.2.4.2. Use innerHTML
        3. 20.2.4.3. Use Event Delegation
        4. 20.2.4.4. Beware of NodeLists
    3. 20.3. Deployment
      1. 20.3.1. Build Process
      2. 20.3.2. Validation
      3. 20.3.3. Compression
        1. 20.3.3.1. File Compression
        2. 20.3.3.2. HTTP Compression
    4. 20.4. Summary
  27. 21. Upcoming APIs
    1. 21.1. The Selectors API
      1. 21.1.1. The querySelector() Method
      2. 21.1.2. The querySelectorAll() Method
      3. 21.1.3. Support and the Future
    2. 21.2. HTML 5
      1. 21.2.1. Character Set Properties
      2. 21.2.2. Class-Related Additions
        1. 21.2.2.1. The getElementsByClassName() method
        2. 21.2.2.2. The classList Property
      3. 21.2.3. Custom Data Attributes
      4. 21.2.4. Cross-Document Messaging
      5. 21.2.5. Media Elements
      6. 21.2.6. The <canvas> Element
        1. 21.2.6.1. Drawing Rectangles
        2. 21.2.6.2. Drawing Paths
        3. 21.2.6.3. Drawing Text
        4. 21.2.6.4. Transformations
        5. 21.2.6.5. Working with Images
      7. 21.2.7. Offline Support
      8. 21.2.8. Changes to History
      9. 21.2.9. Database Storage
      10. 21.2.10. Drag-and-Drop
        1. 21.2.10.1. Drag-and-Drop Events
        2. 21.2.10.2. Custom Drop Targets
        3. 21.2.10.3. The dataTransfer Object
        4. 21.2.10.4. dropEffect and effectAllowed
        5. 21.2.10.5. Additional Members
      11. 21.2.11. The WebSocket Type
      12. 21.2.12. The Future of HTML 5
    3. 21.3. Summary
  28. 22. The Evolution of JavaScript
    1. 22.1. ECMAScript 4/JavaScript 2
      1. 22.1.1. JavaScript 1.5
        1. 22.1.1.1. Constants
        2. 22.1.1.2. Getters and Setters
      2. 22.1.2. JavaScript 1.6
        1. 22.1.2.1. Array Extras
        2. 22.1.2.2. Array and String Generics
      3. 22.1.3. JavaScript 1.7
        1. 22.1.3.1. Block-Level and Other Scopes
        2. 22.1.3.2. Generators
        3. 22.1.3.3. Iterators
        4. 22.1.3.4. Array Comprehensions
        5. 22.1.3.5. Destructuring Assignments
      4. 22.1.4. JavaScript 1.8
        1. 22.1.4.1. Expression Closures
        2. 22.1.4.2. Generator Expressions
        3. 22.1.4.3. Array Reductions
      5. 22.1.5. JavaScript 1.9
      6. 22.1.6. ECMAScript 4 Proposals
      7. 22.1.7. Variable Typing
        1. 22.1.7.1. Strings, Numbers, and Booleans
        2. 22.1.7.2. Nullability
        3. 22.1.7.3. Detecting Types
      8. 22.1.8. Functions
        1. 22.1.8.1. Rest Arguments
        2. 22.1.8.2. Optional Arguments
        3. 22.1.8.3. Generic Functions
      9. 22.1.9. Defining Types
        1. 22.1.9.1. Union Types
        2. 22.1.9.2. Deep Types
        3. 22.1.9.3. Function Types
        4. 22.1.9.4. Parameterized Types
        5. 22.1.9.5. Assigning and Converting Types
      10. 22.1.10. Classes and Interfaces
        1. 22.1.10.1. Class Prototypes
        2. 22.1.10.2. Virtual Properties
        3. 22.1.10.3. Dynamic Classes
        4. 22.1.10.4. Static Members
      11. 22.1.11. Interfaces
      12. 22.1.12. Inheritance
        1. 22.1.12.1. Overriding superclass Methods
        2. 22.1.12.2. Final Classes and Methods
      13. 22.1.13. Namespaces
      14. 22.1.14. Packages
      15. 22.1.15. Other Language Changes
        1. 22.1.15.1. for-each-in
        2. 22.1.15.2. Operator Overloading
        3. 22.1.15.3. Changes to with
        4. 22.1.15.4. Scoping this
        5. 22.1.15.5. Strict Mode
        6. 22.1.15.6. Error Type Detection
        7. 22.1.15.7. Multiline Strings
        8. 22.1.15.8. String Indexing and Array Slicing
        9. 22.1.15.9. Regular Expression Changes
        10. 22.1.15.10. Property Enumeration Setting
        11. 22.1.15.11. Keyword Usage
        12. 22.1.15.12. Date Object Changes
        13. 22.1.15.13. The Vector Class
        14. 22.1.15.14. The Map Class
      16. 22.1.16. The Future of ECMAScript 4
    2. 22.2. ECMAScript 3.1
      1. 22.2.1. Changes to Object Internals
      2. 22.2.2. Static Object Methods
        1. 22.2.2.1. Accessing Prototype Information
        2. 22.2.2.2. Working with Object Properties
      3. 22.2.3. Object Creation
        1. 22.2.3.1. Retrieving Property Names
        2. 22.2.3.2. Object Lock-Down Methods
      4. 22.2.4. Changes to Functions
        1. 22.2.4.1. Changes to Other Types
      5. 22.2.5. Native JSON Support
      6. 22.2.6. Decimals
        1. 22.2.6.1. Decimal Operations
        2. 22.2.6.2. Decimal Comparisons
        3. 22.2.6.3. Decimal Conversions
        4. 22.2.6.4. Decimal Math
        5. 22.2.6.5. Other Decimal Methods
      7. 22.2.7. Usage Subsets
      8. 22.2.8. The Future of ECMAScript 3.1
    3. 22.3. Summary
  29. A. JavaScript Libraries
    1. A.1. General Libraries
      1. A.1.1. Yahoo! User Interface Library (YUI)
      2. A.1.2. Prototype
      3. A.1.3. The Dojo Toolkit
      4. A.1.4. MooTools
      5. A.1.5. jQuery
      6. A.1.6. MochiKit
      7. A.1.7. Ext JS
    2. A.2. Internet Applications
      1. A.2.1. Rico
      2. A.2.2. qooxdoo
    3. A.3. Animation and Effects
      1. A.3.1. script.aculo.us
      2. A.3.2. moo.fx
      3. A.3.3. Lightbox
    4. A.4. Cryptography
      1. A.4.1. JavaScript MD5
      2. A.4.2. JavaScrypt
  30. B. JavaScript Tools
    1. B.1. Debuggers
      1. B.1.1. Microsoft Script Debugger
      2. B.1.2. Microsoft Script Editor
      3. B.1.3. Visual Studio .NET
      4. B.1.4. Visual Web Developer Express
      5. B.1.5. Firebug
      6. B.1.6. Venkman
      7. B.1.7. Drosera
      8. B.1.8. Web Inspector
      9. B.1.9. Aptana Debugger
    2. B.2. Validators
      1. B.2.1. JSLint
      2. B.2.2. JavaScript Lint prototype chaining
    3. B.3. Crunchers
      1. B.3.1. JSMin
      2. B.3.2. Dojo ShrinkSafe
      3. B.3.3. YUI Compressor
    4. B.4. Unit Testing
      1. B.4.1. JsUnit
      2. B.4.2. YUI Test
      3. B.4.3. Dojo Object Harness (DOH)
    5. B.5. Documentation Generators
      1. B.5.1. JsDoc Toolkit
      2. B.5.2. YUI Doc
      3. B.5.3. AjaxDoc
    6. B.6. Secure Execution Environments
      1. B.6.1. AD safe
      2. B.6.2. Caja

Product information

  • Title: Professional, JavaScript® for Web Developers, Second Edition
  • Author(s): Nicholas C. Zakas
  • Release date: January 2009
  • Publisher(s): Wrox
  • ISBN: 9780470227800