Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
JavaScript: The Definitive Guide
Preface
Conventions Used in This Book
Example Code
Errata and How to Contact Us
Acknowledgments
1. Introduction to JavaScript
Core JavaScript
Client-Side JavaScript
Example: A JavaScript Loan Calculator
I. Core JavaScript
2. Lexical Structure
Character Set
Case Sensitivity
Whitespace, Line Breaks, and Format Control Characters
Unicode Escape Sequences
Normalization
Comments
Literals
Identifiers and Reserved Words
Reserved Words
Optional Semicolons
3. Types, Values, and Variables
Numbers
Integer Literals
Floating-Point Literals
Arithmetic in JavaScript
Binary Floating-Point and Rounding Errors
Dates and Times
Text
String Literals
Escape Sequences in String Literals
Working with Strings
Pattern Matching
Boolean Values
null and undefined
The Global Object
Wrapper Objects
Immutable Primitive Values and Mutable Object References
Type Conversions
Conversions and Equality
Explicit Conversions
Object to Primitive Conversions
Variable Declaration
Repeated and Omitted Declarations
Variable Scope
Function Scope and Hoisting
Variables As Properties
The Scope Chain
4. Expressions and Operators
Primary Expressions
Object and Array Initializers
Function Definition Expressions
Property Access Expressions
Invocation Expressions
Object Creation Expressions
Operator Overview
Number of Operands
Operand and Result Type
Lvalues
Operator Side Effects
Operator Precedence
Operator Associativity
Order of Evaluation
Arithmetic Expressions
The + Operator
Unary Arithmetic Operators
Bitwise Operators
Relational Expressions
Equality and Inequality Operators
Comparison Operators
The in Operator
The instanceof Operator
Logical Expressions
Logical AND (&&)
Logical OR (||)
Logical NOT (!)
Assignment Expressions
Assignment with Operation
Evaluation Expressions
eval()
Global eval()
Strict eval()
Miscellaneous Operators
The Conditional Operator (?:)
The typeof Operator
The delete Operator
The void Operator
The Comma Operator (,)
5. Statements
Expression Statements
Compound and Empty Statements
Declaration Statements
var
function
Conditionals
if
else if
switch
Loops
while
do/while
for
for/in
Property enumeration order
Jumps
Labeled Statements
break
continue
return
throw
try/catch/finally
Miscellaneous Statements
with
debugger
“use strict”
Summary of JavaScript Statements
6. Objects
Creating Objects
Object Literals
Creating Objects with new
Prototypes
Object.create()
Querying and Setting Properties
Objects As Associative Arrays
Inheritance
Property Access Errors
Deleting Properties
Testing Properties
Enumerating Properties
Property Getters and Setters
Property Attributes
Legacy API for Getters and Setters
Object Attributes
The prototype Attribute
The class Attribute
The extensible Attribute
Serializing Objects
Object Methods
The toString() Method
The toLocaleString() Method
The toJSON() Method
The valueOf() Method
7. Arrays
Creating Arrays
Reading and Writing Array Elements
Sparse Arrays
Array Length
Adding and Deleting Array Elements
Iterating Arrays
Multidimensional Arrays
Array Methods
join()
reverse()
sort()
concat()
slice()
splice()
push() and pop()
unshift() and shift()
toString() and toLocaleString()
ECMAScript 5 Array Methods
forEach()
map()
filter()
every() and some()
reduce(), reduceRight()
indexOf() and lastIndexOf()
Array Type
Array-Like Objects
Strings As Arrays
8. Functions
Defining Functions
Nested Functions
Invoking Functions
Function Invocation
Method Invocation
Constructor Invocation
Indirect Invocation
Function Arguments and Parameters
Optional Parameters
Variable-Length Argument Lists: The Arguments Object
The callee and caller properties
Using Object Properties As Arguments
Argument Types
Functions As Values
Defining Your Own Function Properties
Functions As Namespaces
Closures
Function Properties, Methods, and Constructor
The length Property
The prototype Property
The call() and apply() Methods
The bind() Method
The toString() Method
The Function() Constructor
Callable Objects
Functional Programming
Processing Arrays with Functions
Higher-Order Functions
Partial Application of Functions
Memoization
9. Classes and Modules
Classes and Prototypes
Classes and Constructors
Constructors and Class Identity
The constructor Property
Java-Style Classes in JavaScript
Augmenting Classes
Classes and Types
The instanceof operator
The constructor property
The Constructor Name
Duck-Typing
Object-Oriented Techniques in JavaScript
Example: A Set Class
Example: Enumerated Types
Standard Conversion Methods
Comparison Methods
Borrowing Methods
Private State
Constructor Overloading and Factory Methods
Subclasses
Defining a Subclass
Constructor and Method Chaining
Composition Versus Subclassing
Class Hierarchies and Abstract Classes
Classes in ECMAScript 5
Making Properties Nonenumerable
Defining Immutable Classes
Encapsulating Object State
Preventing Class Extensions
Subclasses and ECMAScript 5
Property Descriptors
Modules
Objects As Namespaces
Function Scope As a Private Namespace
10. Pattern Matching with Regular Expressions
Defining Regular Expressions
Literal Characters
Character Classes
Repetition
Nongreedy repetition
Alternation, Grouping, and References
Specifying Match Position
Flags
String Methods for Pattern Matching
The RegExp Object
RegExp Properties
RegExp Methods
11. JavaScript Subsets and Extensions
JavaScript Subsets
The Good Parts
Subsets for Security
Constants and Scoped Variables
Destructuring Assignment
Iteration
The for/each Loop
Iterators
Generators
Array Comprehensions
Generator Expressions
Shorthand Functions
Multiple Catch Clauses
E4X: ECMAScript for XML
12. Server-Side JavaScript
Scripting Java with Rhino
Rhino Example
Asynchronous I/O with Node
Node Example: HTTP Server
Node Example: HTTP Client Utilities Module
II. Client-Side JavaScript
13. JavaScript in Web Browsers
Client-Side JavaScript
JavaScript in Web Documents
JavaScript in Web Applications
Embedding JavaScript in HTML
The <script> Element
Scripts in External Files
Script Type
Event Handlers in HTML
JavaScript in URLs
Bookmarklets
Execution of JavaScript Programs
Synchronous, Asynchronous, and Deferred Scripts
Event-Driven JavaScript
Client-Side JavaScript Threading Model
Client-Side JavaScript Timeline
Compatibility and Interoperability
Compatibility Libraries
Graded Browser Support
Feature Testing
Quirks Mode and Standards Mode
Browser Testing
Conditional Comments in Internet Explorer
Accessibility
Security
What JavaScript Can’t Do
The Same-Origin Policy
Relaxing the same-origin policy
Scripting Plug-ins and ActiveX Controls
Cross-Site Scripting
Denial-of-Service Attacks
Client-Side Frameworks
14. The Window Object
Timers
Browser Location and Navigation
Parsing URLs
Loading New Documents
Browsing History
Browser and Screen Information
The Navigator Object
The Screen Object
Dialog Boxes
Error Handling
Document Elements As Window Properties
Multiple Windows and Frames
Opening and Closing Windows
Closing windows
Relationships Between Frames
JavaScript in Interacting Windows
15. Scripting Documents
Overview of the DOM
Selecting Document Elements
Selecting Elements By ID
Selecting Elements by Name
Selecting Elements by Type
Selecting Elements by CSS Class
Selecting Elements with CSS Selectors
document.all[]
Document Structure and Traversal
Documents As Trees of Nodes
Documents As Trees of Elements
Attributes
HTML Attributes As Element Properties
Getting and Setting Non-HTML Attributes
Dataset Attributes
Attributes As Attr Nodes
Element Content
Element Content As HTML
Element Content As Plain Text
Element Content As Text Nodes
Creating, Inserting, and Deleting Nodes
Creating Nodes
Inserting Nodes
Removing and Replacing Nodes
Using DocumentFragments
Example: Generating a Table of Contents
Document and Element Geometry and Scrolling
Document Coordinates and Viewport Coordinates
Querying the Geometry of an Element
Determining the Element at a Point
Scrolling
More on Element Size, Position and Overflow
HTML Forms
Selecting Forms and Form Elements
Form and Element Properties
Form and Element Event Handlers
Push Buttons
Toggle Buttons
Text Fields
Select and Option Elements
Other Document Features
Document Properties
The document.write() Method
Querying Selected Text
Editable Content
16. Scripting CSS
Overview of CSS
The Cascade
CSS History
Shortcut Properties
Nonstandard Properties
CSS Example
Important CSS Properties
Positioning Elements with CSS
The third dimension: z-index
CSS positioning example: Shadowed text
Borders, Margins and Padding
The CSS Box Model and Positioning Details
The border-box model and the box-sizing property
Element Display and Visibility
Color, Transparency, and Translucency
Partial Visibility: overflow and clip
Example: Overlapping Translucent Windows
Scripting Inline Styles
CSS Animations
Querying Computed Styles
Scripting CSS Classes
Scripting Stylesheets
Enabling and Disabling Stylesheets
Querying, Inserting and Deleting Stylesheet Rules
Creating New Stylesheets
17. Handling Events
Types of Events
Legacy Event Types
Form events
Window events
Mouse events
Key events
DOM Events
HTML5 Events
Touchscreen and Mobile Events
Registering Event Handlers
Setting Event Handler Properties
Setting Event Handler Attributes
addEventListener()
attachEvent()
Event Handler Invocation
Event Handler Argument
Event Handler Context
Event Handler Scope
Handler Return Value
Invocation Order
Event Propagation
Event Cancellation
Document Load Events
Mouse Events
Mousewheel Events
Drag and Drop Events
Text Events
Keyboard Events
18. Scripted HTTP
Using XMLHttpRequest
Specifying the Request
Retrieving the Response
Synchronous responses
Decoding the response
Encoding the Request Body
Form-encoded requests
JSON-encoded requests
XML-encoded requests
Uploading a file
multipart/form-data requests
HTTP Progress Events
Upload progress events
Aborting Requests and Timeouts
Cross-Origin HTTP Requests
HTTP by <script>: JSONP
Comet with Server-Sent Events
19. The jQuery Library
jQuery Basics
The jQuery() Function
Queries and Query Results
jQuery Getters and Setters
Getting and Setting HTML Attributes
Getting and Setting CSS Attributes
Getting and Setting CSS Classes
Getting and Setting HTML Form Values
Getting and Setting Element Content
Getting and Setting Element Geometry
Getting and Setting Element Data
Altering Document Structure
Inserting and Replacing Elements
Copying Elements
Wrapping Elements
Deleting Elements
Handling Events with jQuery
Simple Event Handler Registration
jQuery Event Handlers
The jQuery Event Object
Advanced Event Handler Registration
Deregistering Event Handlers
Triggering Events
Custom Events
Live Events
Animated Effects
Simple Effects
Custom Animations
The animation properties object
The animation options object
Canceling, Delaying, and Queuing Effects
Ajax with jQuery
The load() Method
Ajax Utility Functions
jQuery.getScript()
jQuery.getJSON()
jQuery.get() and jQuery.post()
The jQuery.ajax() Function
Common Options
Callbacks
Uncommon options and hooks
Ajax Events
Utility Functions
jQuery Selectors and Selection Methods
jQuery Selectors
Simple selectors
Selector combinations
Selector groups
Selection Methods
Using a selection as context
Reverting to a previous selection
Extending jQuery with Plug-ins
The jQuery UI Library
20. Client-Side Storage
localStorage and sessionStorage
Storage Lifetime and Scope
Storage API
Storage Events
Cookies
Cookie Attributes: Lifetime and Scope
Storing Cookies
Reading Cookies
Cookie Limitations
Storage with Cookies
IE userData Persistence
Application Storage and Offline Webapps
The Application Cache Manifest
Complex manifests
Cache Updates
Offline Web Applications
21. Scripted Media and Graphics
Scripting Images
Unobtrusive Image Rollovers
Scripting Audio and Video
Type Selection and Loading
Controlling Media Playback
Querying Media Status
Media Events
SVG: Scalable Vector Graphics
Graphics in a <canvas>
Drawing Lines and Filling Polygons
Graphics Attributes
Canvas Dimensions and Coordinates
Coordinate System Transforms
Understanding transformations mathematically
Transformation example
Drawing and Filling Curves
Rectangles
Colors, Transparency, Gradients, and Patterns
Line Drawing Attributes
Text
Clipping
Shadows
Images
Compositing
Pixel Manipulation
Hit Detection
Canvas Example: Sparklines
22. HTML5 APIs
Geolocation
History Management
Cross-Origin Messaging
Web Workers
Worker Objects
Worker Scope
Web Worker Examples
Typed Arrays and ArrayBuffers
Blobs
Files As Blobs
Downloading Blobs
Building Blobs
Blob URLs
Reading Blobs
The Filesystem API
Client-Side Databases
Web Sockets
III. Core JavaScript Reference
I. Core JavaScript Reference
arguments[ ]
Arguments
Arguments.callee
Arguments.length
Array
Array.concat()
Array.every()
Array.filter()
Array.forEach()
Array.indexOf()
Array.join()
Array.lastIndexOf()
Array.length
Array.map()
Array.pop()
Array.push()
Array.reduce()
Array.reduceRight()
Array.reverse()
Array.shift()
Array.slice()
Array.some()
Array.sort()
Array.splice()
Array.toLocaleString()
Array.toString()
Array.unshift()
Boolean
Boolean.toString()
Boolean.valueOf()
Date
Date.getDate()
Date.getDay()
Date.getFullYear()
Date.getHours()
Date.getMilliseconds()
Date.getMinutes()
Date.getMonth()
Date.getSeconds()
Date.getTime()
Date.getTimezoneOffset()
Date.getUTCDate()
Date.getUTCDay()
Date.getUTCFullYear()
Date.getUTCHours()
Date.getUTCMilliseconds()
Date.getUTCMinutes()
Date.getUTCMonth()
Date.getUTCSeconds()
Date.getYear()
Date.now()
Date.parse()
Date.setDate()
Date.setFullYear()
Date.setHours()
Date.setMilliseconds()
Date.setMinutes()
Date.setMonth()
Date.setSeconds()
Date.setTime()
Date.setUTCDate()
Date.setUTCFullYear()
Date.setUTCHours()
Date.setUTCMilliseconds()
Date.setUTCMinutes()
Date.setUTCMonth()
Date.setUTCSeconds()
Date.setYear()
Date.toDateString()
Date.toGMTString()
Date.toISOString()
Date.toJSON
Date.toLocaleDateString()
Date.toLocaleString()
Date.toLocaleTimeString()
Date.toString()
Date.toTimeString()
Date.toUTCString()
Date.UTC()
Date.valueOf()
decodeURI()
decodeURIComponent()
encodeURI()
encodeURIComponent()
Error
Error.message
Error.name
Error.toString()
escape()
eval()
EvalError
Function
Function.apply()
Function.arguments[]
Function.bind()
Function.call()
Function.caller
Function.length
Function.prototype
Function.toString()
Global
Infinity
isFinite()
isNaN()
JSON
JSON.parse()
JSON.stringify()
Math
Math.abs()
Math.acos()
Math.asin()
Math.atan()
Math.atan2()
Math.ceil()
Math.cos()
Math.E
Math.exp()
Math.floor()
Math.LN10
Math.LN2
Math.log()
Math.LOG10E
Math.LOG2E
Math.max()
Math.min()
Math.PI
Math.pow()
Math.random()
Math.round()
Math.sin()
Math.sqrt()
Math.SQRT1_2
Math.SQRT2
Math.tan()
NaN
Number
Number.MAX_VALUE
Number.MIN_VALUE
Number.NaN
Number.NEGATIVE_INFINITY
Number.POSITIVE_INFINITY
Number.toExponential()
Number.toFixed()
Number.toLocaleString()
Number.toPrecision()
Number.toString()
Number.valueOf()
Object
Object.constructor
Object.create()
Object.defineProperties()
Object.defineProperty()
Object.freeze()
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyNames()
Object.getPrototypeOf()
Object.hasOwnProperty()
Object.isExtensible()
Object.isFrozen()
Object.isPrototypeOf()
Object.isSealed()
Object.keys()
Object.preventExtensions()
Object.propertyIsEnumerable()
Object.seal()
Object.toLocaleString()
Object.toString()
Object.valueOf()
parseFloat()
parseInt()
RangeError
ReferenceError
RegExp
RegExp.exec()
RegExp.global
RegExp.ignoreCase
RegExp.lastIndex
RegExp.source
RegExp.test()
RegExp.toString()
String
String.charAt()
String.charCodeAt()
String.concat()
String.fromCharCode()
String.indexOf()
String.lastIndexOf()
String.length
String.localeCompare()
String.match()
String.replace()
String.search()
String.slice()
String.split()
String.substr()
String.substring()
String.toLocaleLowerCase()
String.toLocaleUpperCase()
String.toLowerCase()
String.toString()
String.toUpperCase()
String.trim()
String.valueOf()
SyntaxError
TypeError
undefined
unescape()
URIError
IV. Client-Side JavaScript Reference
II. Client-Side JavaScript Reference
ApplicationCache
ArrayBuffer
ArrayBufferView
Attr
Audio
BeforeUnloadEvent
Blob
BlobBuilder
Button
Canvas
CanvasGradient
CanvasPattern
CanvasRenderingContext2D
ClientRect
CloseEvent
Comment
Console
ConsoleCommandLine
CSS2Properties
CSSRule
CSSStyleDeclaration
CSSStyleSheet
DataTransfer
DataView
Document
DocumentFragment
DocumentType
DOMException
DOMImplementation
DOMSettableTokenList
DOMTokenList
Element
ErrorEvent
Event
EventSource
EventTarget
FieldSet
File
FileError
FileReader
FileReaderSync
Form
FormControl
FormData
FormValidity
Geocoordinates
Geolocation
GeolocationError
Geoposition
HashChangeEvent
History
HTMLCollection
HTMLDocument
HTMLElement
HTMLFormControlsCollection
HTMLOptionsCollection
IFrame
Image
ImageData
Input
jQuery
KeyEvent
Label
Link
Location
MediaElement
MediaError
MessageChannel
MessageEvent
MessagePort
Meter
MouseEvent
Navigator
Node
NodeList
Option
Output
PageTransitionEvent
PopStateEvent
ProcessingInstruction
Progress
ProgressEvent
Screen
Script
Select
Storage
StorageEvent
Style
Table
TableCell
TableRow
TableSection
Text
TextArea
TextMetrics
TimeRanges
TypedArray
URL
Video
WebSocket
Window
Worker
WorkerGlobalScope
WorkerLocation
WorkerNavigator
XMLHttpRequest
XMLHttpRequestUpload
Index
About the Author
Colophon
← Prev
Back
Next →
← Prev
Back
Next →