You are previewing Eloquent JavaScript.
O'Reilly logo
Eloquent JavaScript

Book Description

Eloquent JavaScript is a guide to JavaScript that focuses on good programming techniques rather than offering a mish-mash of cut-and-paste effects. The author teaches you how to leverage JavaScript's grace and precision to write real browser-based applications. The book begins with the fundamentals of programming—variables, control structures, functions, and data structures—then moves on to more complex topics, like object-oriented programming, regular expressions, and browser events. With clear examples and a focus on elegance, Eloquent JavaScript will have you fluent in the language of the web in no time.

Table of Contents

  1. Eloquent JavaScript
    1. Introduction
      1. On Programming
      2. Why Language Matters
      3. What Is JavaScript?
      4. Trying Programs
      5. Overview of This Book
      6. Typographic Conventions
    2. 1. Basic JavaScript: Values, Variables, and Control Flow
      1. Values
        1. Numbers
        2. Arithmetic
        3. Strings
        4. Unary Operators
        5. Boolean Values, Comparisons, and Boolean Logic
        6. Expressions and Statements
      2. Variables
        1. Keywords and Reserved Words
      3. The Environment
        1. Functions
        2. prompt and confirm
        3. The print Function
        4. Modifying the Environment
      4. Program Structure
        1. Conditional Execution
        2. while and do Loops
        3. Indenting Code
        4. for Loops
        5. Breaking Out of a Loop
        6. Updating Variables Succinctly
        7. Dispatching on a Value with switch
        8. Capitalization
        9. Comments
      5. More on Types
        1. Undefined Values
        2. Automatic Type Conversion
        3. Dangers of Automatic Type Conversion
        4. More on && and ||
    3. 2. Functions
      1. The Anatomy of a Function Definition
        1. Definition Order
        2. Local Variables
        3. Nested Scope
        4. The Stack
        5. Function Values
        6. Closure
        7. Optional Arguments
      2. Techniques
        1. Avoiding Repetition
        2. Purity
        3. Recursion
    4. 3. Data Structures: Objects and Arrays
      1. The Problem: Aunt Emily's Cats
      2. Basic Data Structures
        1. Properties
        2. Object Values
        3. Objects as Sets
        4. Mutability
        5. Objects as Collections: Arrays
        6. Methods
      3. Solving the Problem of Aunt Emily's Cats
        1. Separating Paragraphs
        2. Finding Relevant Paragraphs
        3. Extracting Cat Names
        4. The Full Algorithm
        5. Cleaning Up the Code
        6. Date Representation
        7. Date Extraction
        8. Gathering More Information
        9. Data Presentation
      4. Some More Theory
        1. The arguments Object
        2. Tying Up a Loose End
        3. The Math Object
        4. Enumerable Properties
    5. 4. Error Handling
      1. Types of Problems
        1. Programmer Mistakes
        2. Run-Time Errors
      2. Handling Errors
        1. Returning a Special Value
        2. Exceptions
        3. Cleaning Up After Exceptions
        4. Error Objects
        5. Unhandled Exceptions
        6. Selective Catching
      3. Automated Testing
    6. 5. Functional Programming
      1. Abstraction
      2. Higher-Order Functions
        1. Modifying Functions
        2. The reduce Function
        3. Mapping Arrays
      3. The Sad Story of the Recluse
        1. HTML
        2. The Recluse's Text File
        3. Finding Paragraphs
        4. Emphasis and Footnotes
        5. Moving the Footnotes
        6. Generating HTML
        7. Converting the Recluse's Book
      4. Other Functional Tricks
        1. Operator Functions
        2. Partial Application
        3. Composition
    7. 6. Object-Oriented Programming
      1. Objects
        1. Defining Methods
        2. Constructors
        3. Building from Prototype
        4. Constructors and Prototypes
        5. Prototype Pollution
        6. Objects as Dictionaries
        7. Specifying an Interface
      2. Building an Ecosystem Simulation
        1. Defining the Terrarium
        2. Points in Space
        3. Representing the Grid
        4. A Bug's Programming Interface
        5. The Terrarium Object
        6. this and Its Scope
        7. Animating Life
        8. It Moves
        9. More Life Forms
        10. Polymorphism
      3. A More Lifelike Simulation
        1. Inheritance
        2. Keeping Track of Energy
        3. Adding Plant Life
        4. The Herbivore
        5. Bringing It to Life
        6. Artificial Stupidity
      4. Prototypal Inheritance
        1. Type-Definition Utilities
        2. Prototypes as Types
        3. A World of Objects
        4. The instanceof Operator
        5. Mixing Types
    8. 7. Modularity
      1. Modules
        1. An Example
        2. Modules as Files
      2. The Shape of a Module
        1. Functions as Local Namespaces
        2. Module Objects
      3. Interface Design
        1. Predictability
        2. Composability
        3. Layered Interfaces
        4. Argument Objects
      4. Libraries
    9. 8. Regular Expressions
      1. Syntax
        1. Matching Sets of Characters
        2. Matching Word and String Boundaries
        3. Repeating Patterns
        4. Grouping Subexpressions
        5. Choosing Between Alternatives
      2. Matching and Replacing
        1. The match Method
        2. Regular Expressions and the replace Method
        3. Dynamically Creating RegExp Objects
      3. Parsing an .ini File
      4. Conclusion
    10. 9. Web Programming: A Crash Course
      1. The Internet
        1. URLs
        2. Server-Side Programming
        3. Client-Side Programming
      2. Basic Web Scripting
        1. The window Object
        2. The document Object
        3. Timers
        4. Forms
        5. Scripting a Form
        6. Autofocus
      3. Browser Incompatibility
      4. Further Reading
    11. 10. The Document Object Model
      1. DOM Elements
        1. Node Links
        2. Types of Nodes
        3. The innerHTML Property
        4. Finding Your Node
        5. Node Creation
        6. A Creation Helper Function
        7. Moving Nodes Around
        8. An Implementation of print
      2. Style Sheets
        1. The style Property
        2. Hiding Nodes
        3. Positioning
        4. Controlling Node Size
      3. Word of Caution
    12. 11. Browser Events
      1. Event Handlers
        1. Registering a Handler
        2. Event Objects
        3. Mouse-Related Event Types
        4. Keyboard Events
        5. Stopping an Event
        6. Normalizing Event Objects
        7. Tracking Focus
        8. Form Events
        9. Window Events
      2. Example: Implementing Sokoban
        1. Level Input Format
        2. Program Design
        3. Game Board Representation
        4. The Controller Object
    13. 12. HTTP requests
      1. The HTTP Protocol
      2. The XMLHttpRequest API
        1. Creating a Request Object
        2. Simple Requests
        3. Making Asynchronous Requests
        4. Fetching XML Data
        5. Reading JSON Data
        6. A Basic Request Wrapper
      3. Learning HTTP
    14. Index
    15. About the Author
    16. Colophon
    17. A. Updates