Learning JavaScript

Book description

As web browsers have become more capable and standards compliant, JavaScript has grown in prominence. JavaScript lets designers add sparkle and life to web pages, while more complex JavaScript has led to the rise of Ajax -- the latest rage in web development that allows developers to create powerful and more responsive applications in the browser window.

Learning JavaScript introduces this powerful scripting language to web designers and developers in easy-to-understand terms. Using the latest examples from modern browser development practices, this book teaches you how to integrate the language with the browser environment, and how to practice proper coding techniques for standards-compliant web sites. By the end of the book, you'll be able to use all of the JavaScript language and many of the object models provided by web browsers, and you'll even be able to create a basic Ajax application.

Table of contents

  1. Learning JavaScript
    1. Preface
      1. Audience
      2. Assumptions and Approach
      3. Conventions Used in This Book
      4. Using Code Examples
      5. How to Contact Us
      6. Safari® Enabled
      7. Acknowledgments
    2. 1. Introduction and First Looks
      1. Twisted History: Specs and Implementations
      2. Cross-Browser Incompatibility and Other Common JavaScript Myths
      3. What You Can Do with JavaScript
      4. First Look at JavaScript: “Hello World!”
        1. The script Tag
        2. JavaScript Code Location
        3. Hiding the Script
        4. JavaScript Files
        5. Comments
        6. Browser Objects
        7. JavaScript Built-in Objects
        8. JavaScript User-Defined Functions
        9. Event Handlers
        10. The var Keyword and Scope
        11. The Property Operator
        12. Statements
        13. What You Didn’t See
      5. The JavaScript Sandbox
      6. Accessibility and JavaScript Best Practices
        1. Accessibility Guidelines
        2. noscript
        3. An Alternative to noscript
        4. Using Your Browser and Other Developer Tools
    3. 2. JavaScript Data Types and Variables
      1. Identifying Variables
        1. Naming Guidelines
        2. The Prototype Effect and the Newer Naming Conventions
      2. Scope
      3. Simple Types
        1. The String Data Type
        2. The Boolean Data Type
        3. The Number Data Type
        4. Null and Undefined
      4. Constants: Named but Not Variables
      5. Questions
    4. 3. Operators and Statements
      1. Format of a JavaScript Statement
      2. Simple Statements
        1. The Assignment Statement
        2. Arithmetic Statements
        3. The Unary Operators
        4. Precedence of Operators
        5. Handy Shortcut: Assignment with Operation
        6. Bitwise Operators
      3. Conditional Statements and Program Flow
        1. if...else
        2. The switch Conditional Statement
      4. The Conditional Operators
        1. The Equality and the Identity (String Equality) Operators
        2. Other Relational Operators
        3. The One and Only JavaScript Ternary Operator
      5. The Logical Operators
      6. Advanced Statements: The Loops
        1. The while Loop
        2. The do...while Loop
        3. The for Loops
      7. Questions
    5. 4. The JavaScript Objects
      1. The Object Constructor
      2. The Number Object
      3. The String Object
      4. Regular Expressions and RegExp
        1. The RegExp Methods: test and exec
        2. Working with Regular Expressions
      5. Purposeful Objects: Date and Math
        1. The Date
        2. Math
        3. The Math Methods
      6. JavaScript Arrays
        1. Constructing Arrays
        2. FIFO Queues
      7. Associative Arrays: The Arrays That Aren’t
      8. Questions
    6. 5. Functions
      1. Defining a Function: Let Me Count the Ways
        1. Declarative Functions
          1. A reminder on function naming conventions
        2. Function Returns and Arguments
        3. Anonymous Functions
        4. Function Literals
        5. Function Type Summary
      2. Callback Functions
      3. Functions and Recursion
      4. Nested Functions, Function Closure, and Memory Leaks
      5. Function As Object
      6. Questions
    7. 6. Catching Events
      1. The Event Handler at DOM Level 0
        1. The Event Object
        2. Event Bubbling
        3. Event Handlers and this
        4. Generating Events
      2. Questions
    8. 7. Forms and JiT Validation
      1. Accessing the Form
      2. Attaching Events to Forms: Different Approaches
      3. Selection
        1. Dynamically Modifying the Selection
        2. Selection and JiT Validation
      4. Radio Buttons and Checkboxes
        1. The textarea, text, hidden, and password Input Elements
        2. JiT Does Text
      5. Input Fields and JiT Regular Expressions
      6. Questions
    9. 8. The Sandbox and Beyond: Cookies, Connectivity, and Piracy
      1. The Sandbox
        1. Same-Origin Security Policy
        2. Using document.domain
      2. All About Cookies
        1. Storing and Reading Cookies
      3. Alternative Storage Techniques
        1. Communicating Outside the Box
        2. The Flash SO and Dojo Storage
        3. Could You, Should You?
      4. Cross-Site Scripting (XSS)
        1. The Injectors
        2. What You Can Do
      5. Questions
    10. 9. The Basic Browser Objects
      1. BOM at a Glance
      2. The window Object
        1. The Dialogs: Alert, Confirm, and Prompt
        2. Creating Custom Windows
        3. Cross-Window Communication
        4. Modifying the Window
        5. Timers
      3. Frames and Location
        1. More On Location
        2. Remote Scripting with the iframe
      4. history, screen, and navigator
        1. history
        2. screen
        3. navigator
        4. One Page, Three Objects
        5. document
        6. Links
        7. Images
      5. The all Collection, Inner/Outer HTML and Text, and Old and New Documents
      6. Something Old, Something New
      7. Questions
    11. 10. DOM: The Document Object Model
      1. A Tale of Two Interfaces
      2. The DOM and Compliant Browsers
      3. The DOM HTML API
        1. The HTML Objects and Their Properties
        2. Accessing HTML Objects and Browser Differences
      4. Understanding the DOM: The Core API
        1. The DOM Tree
        2. Node Properties and Methods
        3. Traversing the Tree with the Node
      5. The DOM Core Document Object
      6. Element and Access in Context
      7. Modifying the Tree
      8. Questions
    12. 11. Creating Custom JavaScript Objects
      1. The JavaScript Object and Prototyping
        1. Prototyping
      2. Creating Your Own Custom JavaScript Objects
        1. Enter the Function
        2. Public and Private Properties and Where this Enters the Picture
      3. Object Detection, Encapsulation, and Cross-Browser Objects
        1. Object Detection
        2. Encapsulating Objects
      4. Chaining Constructors and JS Inheritance
      5. One-Off Objects
      6. Advanced Error-Handling Techniques (try, throw, catch)
      7. What’s New in JavaScript
        1. Change Just Enough
        2. Scaling and the Next 10 Years
      8. Questions
    13. 12. Building Dynamic Web Pages: Adding Style to Your Script
      1. DHTML: JavaScript, CSS, and DOM
        1. The style Property
      2. Fonts and Text
        1. Font Style Properties
        2. The Text Properties
      3. Position and Movement
        1. Drag and Drop
      4. Size and Clipping
        1. Overflow and Dynamic Content
        2. The Clipping Rectangle
      5. Display, Visibility, and Opacity
        1. Right Tool for Right Effect
        2. Just-in-Time Information
        3. Collapsing Forms
      6. Questions
    14. 13. Moving Outside the Page with Ajax
      1. Ajax: It’s Not Only Code
        1. PermaWhat?
        2. Security and Workarounds
        3. Ajax Best Practices
      2. How Ajax Works
      3. Hello Ajax World!
      4. The Ajax Object: XMLHttpRequest and IE’s ActiveX Objects
        1. Object, Object, Who Has the Object?
        2. The XMLHttpRequest Methods
      5. Working with XML—or Not
        1. Yes to XML
        2. JavaScript Object Notation
      6. Google Maps
      7. Questions
    15. 14. Good News: Juicy Libraries! Amazing Web Services! Fun APIs!
      1. Before Jumping In, A Word of Caution
      2. Working with Prototype
        1. Download, Install, Use
        2. The Helper Functions and the JavaScript Extensions
        3. Some Specialized Prototype Objects
        4. A Compliment and a Caveat
      3. Script.aculo.us: More Than the Sum of Its Periods
        1. Usage
        2. A Gander at Effects
      4. Sabre’s Rico
        1. Rounded Corners
      5. Dojo
        1. Installing and Setting Up Dojo
        2. Dojo Widgets
      6. The Yahoo! UI
      7. MochiKit
        1. Logging
      8. Questions
    16. A. Answers
      1. Chapter 2
      2. Chapter 3
      3. Chapter 4
      4. Chapter 5
      5. Chapter 6
      6. Chapter 7
      7. Chapter 8
      8. Chapter 9
      9. Chapter 10
      10. Chapter 11
      11. Chapter 12
      12. Chapter 13
      13. Chapter 14
    17. Index

Product information

  • Title: Learning JavaScript
  • Author(s): Shelley Powers
  • Release date: October 2006
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596527464