Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Eloquent JavaScript: A Modern Introduction to Programming
Dedication
Praise for the First Edition of Eloquent Javascript
Introduction
On Programming
Why Language Matters
What Is JavaScript?
Code, and What to Do with It
Overview of This Book
Typographic Conventions
I. Language
1. Values, Types, and Operators
Values
Numbers
Arithmetic
Special Numbers
Strings
Unary Operators
Boolean Values
Comparisons
Logical Operators
Undefined Values
Automatic Type Conversion
Short-Circuiting of Logical Operators
Summary
2. Program Structure
Expressions and Statements
Variables
Keywords and Reserved Words
The Environment
Functions
The console.log Function
Return Values
Prompt and Confirm
Control Flow
Conditional Execution
while and do Loops
Indenting Code
for Loops
Breaking Out of a Loop
Updating Variables Succinctly
Dispatching on a Value with switch
Capitalization
Comments
Summary
Exercises
Looping a Triangle
FizzBuzz
Chess Board
3. Functions
Defining a Function
Parameters and Scopes
Nested Scopes
Functions as Values
Declaration Notation
The Call Stack
Optional Arguments
Closure
Recursion
Growing Functions
Functions and Side Effects
Summary
Exercises
Minimum
Recursion
Bean Counting
4. Data Structures: Objects and Arrays
The Weresquirrel
Data Sets
Properties
Methods
Objects
Mutability
The Lycanthrope’s Log
Computing Correlation
Objects as Maps
The Final Analysis
Further Arrayology
Strings and Their Properties
The arguments Object
The Math Object
The Global Object
Summary
Exercises
The Sum of a Range
Reversing an Array
A List
Deep Comparison
5. Higher-Order Functions
Abstraction
Abstracting Array Traversal
Higher-Order Functions
Passing Along Arguments
JSON
Filtering an Array
Transforming with map
Summarizing with reduce
Composability
The Cost
Great-great-great-great-...
Binding
Summary
Exercises
Flattening
Mother-Child Age Difference
Historical Life Expectancy
Every and Then Some
6. The Secret Life of Objects
History
Methods
Prototypes
Constructors
Overriding Derived Properties
Prototype Interference
Prototype-less Objects
Polymorphism
Laying Out a Table
Getters and Setters
Inheritance
The instanceof Operator
Summary
Exercises
A Vector Type
Another Cell
Sequence Interface
7. Project: Electronic Life
Definition
Representing Space
A Critter’s Programming Interface
The World Object
this and Its Scope
Animating Life
It Moves
More Life-forms
A More Lifelike Simulation
Action Handlers
Populating the New World
Bringing the World to Life
Exercises
Artificial Stupidity
Predators
8. Bugs and Error Handling
Programmer Mistakes
Strict Mode
Testing
Debugging
Error Propagation
Exceptions
Cleaning Up After Exceptions
Selective Catching
Assertions
Summary
Exercises
Retry
The Locked Box
9. Regular Expressions
Creating a Regular Expression
Testing for Matches
Matching a Set of Characters
Repeating Parts of a Pattern
Grouping Subexpressions
Matches and Groups
The Date Type
Word and String Boundaries
Choice Patterns
The Mechanics of Matching
Backtracking
The replace Method
Greed
Dynamically Creating RegExp Objects
The search Method
The lastIndex Property
Looping over Matches
Parsing an INI File
International Characters
Summary
Exercises
Regexp Golf
Quoting Style
Numbers Again
10. Modules
Why Modules Help
Namespacing
Reuse
Decoupling
Using Functions as Namespaces
Objects as Interfaces
Detaching from the Global Scope
Evaluating Data as Code
The require Function
Slow-Loading Modules
Interface Design
Predictability
Composability
Layered Interfaces
Summary
Exercises
Month Names
A Return to Electronic Life
Circular Dependencies
11. Project: A Programming Language
Parsing
The Evaluator
Special Forms
The Environment
Functions
Compilation
Cheating
Exercises
Arrays
Closure
Comments
Fixing Scope
II. Browser
12. Javascript and The Browser
Networks and the Internet
The Web
HTML
HTML and JavaScript
In the Sandbox
Compatibility and the Browser Wars
13. The Document Object Model
Document Structure
Trees
The Standard
Moving Through the Tree
Finding Elements
Changing the Document
Creating Nodes
Attributes
Layout
Styling
Cascading Styles
Query Selectors
Positioning and Animating
Summary
Exercises
Build a Table
Elements by Tag Name
The Cat’s Hat
14. Handling Events
Event Handlers
Events and DOM Nodes
Event Objects
Propagation
Default Actions
Key Events
Mouse Clicks
Mouse Motion
Scroll Events
Focus Events
Load Event
Script Execution Timeline
Setting Timers
Debouncing
Summary
Exercises
Censored Keyboard
Mouse Trail
Tabs
15. Project: A Platform Game
The Game
The Technology
Levels
Reading a Level
Actors
Encapsulation as a Burden
Drawing
Motion and Collision
Actors and Actions
Tracking Keys
Running the Game
Exercises
Game Over
Pausing the Game
16. Drawing on Canvas
SVG
The Canvas Element
Filling and Stroking
Paths
Curves
Drawing a Pie Chart
Text
Images
Transformation
Storing and Clearing Transformations
Back to the Game
Choosing a Graphics Interface
Summary
Exercises
Shapes
The Pie Chart
A Bouncing Ball
Precomputed Mirroring
17. HTTP
The Protocol
Browsers and HTTP
XMLHttpRequest
Sending a Request
Asynchronous Requests
Fetching XML Data
HTTP Sandboxing
Abstracting Requests
Promises
Appreciating HTTP
Security and HTTPS
Summary
Exercises
Content Negotiation
Waiting for Multiple Promises
18. Forms and Form Fields
Fields
Focus
Disabled Fields
The Form as a Whole
Text Fields
Checkboxes and Radio Buttons
Select Fields
File Fields
Storing Data Client-Side
Summary
Exercises
A JavaScript Workbench
Autocompletion
Conway’s Game of Life
19. Project: A Paint Program
Implementation
Building the DOM
The Foundation
Tool Selection
Color and Brush Size
Saving
Loading Image Files
Finishing Up
Exercises
Rectangles
Color Picker
Flood Fill
III. Beyond
20. Node.js
Background
Asynchronicity
The node Command
Modules
Installing with NPM
The Filesystem Module
The HTTP Module
Streams
A Simple File Server
Error Handling
Summary
Exercises
Content Negotiation, Again
Fixing a Leak
Creating Directories
A Public Space on the Web
21. Project: Skill-Sharing Website
Design
Long Polling
HTTP Interface
The Server
Routing
Serving Files
Talks as Resources
Long-Polling Support
The Client
HTML
Starting up
Displaying Talks
Updating the Server
Noticing Changes
Exercises
Disk Persistence
Comment Field Resets
Better Templates
The Unscriptables
22. Javascript and Performance
Staged Compilation
Graph Layout
Defining a Graph
A First Force-Directed Layout Function
Profiling
Function Inlining
Going Back to Old-school Loops
Avoiding Work
Creating Less Garbage
Garbage Collection
Writing to Objects
Dynamic Types
Summary
Exercises
Pathfinding
Timing
Optimizing
A. Exercise Hints
Program Structure
Looping a Triangle
FizzBuzz
Chess Board
Functions
Minimum
Recursion
Bean Counting
Data Structures: Objects and Arrays
The Sum of a Range
Reversing an Array
A List
Deep Comparison
Higher-Order Functions
Mother-Child Age Difference
Historical Life Expectancy
Every and Then Some
The Secret Life of Objects
A Vector Type
Another Cell
Sequence Interface
Project: Electronic Life
Artificial Stupidity
Predators
Bugs and Error Handling
Retry
The Locked Box
Regular Expressions
Quoting Style
Numbers Again
Modules
Month Names
A Return to Electronic Life
Circular Dependencies
Project: A Programming Language
Arrays
Closure
Comments
Fixing Scope
The Document Object Model
Build a Table
Elements by Tag Name
Handling Events
Censored Keyboard
Mouse Trail
Tabs
Project: A Platform Game
Game Over
Pausing the Game
Drawing on Canvas
Shapes
The Pie Chart
A Bouncing Ball
Precomputed Mirroring
HTTP
Content Negotiation
Waiting for Multiple Promises
Forms and Form Fields
A JavaScript Workbench
Autocompletion
Conway’s Game of Life
Project: A Paint Program
Rectangles
Color Picker
Flood Fill
Node.js
Content Negotiation, Again
Fixing a Leak
Creating Directories
A Public Space on the Web
Project: Skill-Sharing Website
Disk Persistence
Comment Field Resets
Better Templates
The Unscriptables
JavaScript and Performance
Pathfinding
Optimizing
Updates
Index
About the Author
Copyright
← Prev
Back
Next →
← Prev
Back
Next →