Wrox Home  
Search

Topic: Web

Professional JavaScript for Web Developers, 3rd Edition (1118026691) cover image

Professional JavaScript for Web Developers, 3rd Edition

Nicholas C. Zakas
ISBN: 978-1-118-02669-4
Paperback
960 pages
January 2012
View Most Recent Edition of This Title
Other Available Formats: Wiley E-Text
This title is out-of-print and not currently available for purchase from this site.


About This Title  |  Download Code  |  Errata  |  P2P Forum for This Title

Foreword xxxi

Introduction xxxiii

Chapter 1: What is Javascript? 1

A Short History 2

JavaScript Implementations 3

ECMAScript 3

The Document Object Model (DOM) 6

The Browser Object Model (BOM) 9

JavaScript Versions 10

Summary 11

Chapter 2: Javascript in Html 13

The <script> Element 13

Tag Placement 16

Deferred Scripts 16

Asynchronous Scripts 17

Changes in XHTML 18

Deprecated Syntax 20

Inline Code versus External Files 20

Document Modes 20

The <noscript> Element 22

Summary 22

Chapter 3: Language Basics 25

Syntax 25

Case-sensitivity 25

Identifiers 26

Comments 26

Strict Mode 27

Statements 27

Keywords and Reserved Words 28

Variables 29

Data Types 31

The typeof Operator 31

The Undefi ned Type 32

The Null Type 33

The Boolean Type 34

The Number Type 35

The String Type 41

The Object Type 44

Operators 45

Unary Operators 46

Bitwise Operators 49

Boolean Operators 56

Multiplicative Operators 59

Additive Operators 61

Relational Operators 63

Equality Operators 65

Conditional Operator 67

Assignment Operators 67

Comma Operator 68

Statements 69

The if Statement 69

The do-while Statement 70

The while Statement 70

The for Statement 71

The for-in Statement 72

Labeled Statements 73

The break and continue Statements 73

The with Statement 75

The switch Statement 76

Functions 78

Understanding Arguments 80

No Overloading 83

Summary 83

Chapter 4: Variables, Scope, and Memory 85

Primitive and Reference Values 85

Dynamic Properties 86

Copying Values 86

Argument Passing 88

Determining Type 89

Execution Context and Scope 90

Scope Chain Augmentation 92

No Block-Level Scopes 93

Garbage Collection 96

Mark-and-Sweep 96

Reference Counting 97

Performance 98

Managing Memory 99

Summary 100

Chapter 5: Reference Types 103

The Object Type 104

The Array Type 106

Detecting Arrays 110

Conversion Methods 110

Stack Methods 112

Queue Methods 113

Reordering Methods 114

Manipulation Methods 116

Location Methods 118

Iterative Methods 119

Reduction Methods 121

The Date Type 122

Inherited Methods 124

Date-Formatting Methods 125

Date/Time Component Methods 126

The RegExp Type 128

RegExp Instance Properties 131

RegExp Instance Methods 132

RegExp Constructor Properties 134

Pattern Limitations 136

The Function Type 136

No Overloading (Revisited) 138

Function Declarations versus Function Expressions 138

Functions as Values 139

Function Internals 141

Function Properties and Methods 143

Primitive Wrapper Types 146

The Boolean Type 148

The Number Type 149

The String Type 151

Singleton Built-in Objects 161

The Global Object 162

The Math Object 166

Summary 170

Chapter 6: Object-Oriented Programming 173

Understanding Objects 173

Types of Properties 174

Defining Multiple Properties 178

Reading Property Attributes 179

Object Creation 180

The Factory Pattern 180

The Constructor Pattern 181

The Prototype Pattern 184

Combination Constructor/Prototype Pattern 197

Dynamic Prototype Pattern 198

Parasitic Constructor Pattern 199

Durable Constructor Pattern 200

Inheritance 201

Prototype Chaining 202

Constructor Stealing 207

Combination Inheritance 209

Prototypal Inheritance 210

Parasitic Inheritance 211

Parasitic Combination Inheritance 212

Summary 215

Chapter 7: Function Expressions 217

Recursion 220

Closures 221

Closures and Variables 224

The this Object 225

Memory Leaks 227

Mimicking Block Scope 228

Private Variables 231

Static Private Variables 232

The Module Pattern 234

The Module-Augmentation Pattern 236

Summary 237

Chapter 8: The Browser Object Model 239

The window Object 239

The Global Scope 240

Window Relationships and Frames 241

Window Position 244

Window Size 245

Navigating and Opening Windows 247

Intervals and Timeouts 251

System Dialogs 253

The location Object 255

Query String Arguments 256

Manipulating the Location 257

The Navigator Object 259

Detecting Plug-ins 262

Registering Handlers 264

The screen Object 265

The history Object 267

Summary 268

Chapter 9: Client Detection 271

Capability Detection 271

Safer Capability Detection 273

Capability Detection is Not Browser Detection 274

Quirks Detection 275

User-Agent Detection 276

History 277

Working with User-Agent Detection 286

The Complete Script 303

Usage 306

Summary 306

Chapter 10: The Document Object Model 309

Hierarchy of Nodes 310

The Node Type 310

The Document Type 316

The Element Type 326

The Text Type 337

The Comment Type 341

The CDATASection Type 342

The DocumentType Type 343

The DocumentFragment Type 344

The Attr Type 345

Working with the DOM 346

Dynamic Scripts 346

Dynamic Styles 348

Manipulating Tables 350

Using NodeLists 353

Summary 354

Chapter 11: Dom Extensions 357

Selectors API 357

The querySelector() Method 358

The querySelectorAll() Method 358

The matchesSelector() Method 359

Element Traversal 360

HTML5 361

Class-Related Additions 361

Focus Management 364

Changes to HTMLDocument 364

Character Set Properties 366

Custom Data Attributes 366

Markup Insertion 367

The scrollIntoView() Method 372

Proprietary Extensions 372

Document Mode 373

The children Property 374

The contains() Method 374

Markup Insertion 376

Scrolling 379

Summary 379

Chapter 12: DOM Levels 2 and 3 381

DOM Changes 382

XML Namespaces 382

Other Changes 386

Styles 390

Accessing Element Styles 391

Working with Style Sheets 396

Element Dimensions 401

Traversals 408

NodeIterator 410

TreeWalker 413

Ranges 415

Ranges in the DOM 415

Ranges in Internet Explorer 8 and Earlier 424

Summary 428

Chapter 13: Events 431

Event Flow 432

Event Bubbling 432

Event Capturing 433

DOM Event Flow 433

Event Handlers 434

HTML Event Handlers 434

DOM Level 0 Event Handlers 437

DOM Level 2 Event Handlers 438

Internet Explorer Event Handlers 439

Cross-Browser Event Handlers 441

The Event Object 442

The DOM Event Object 442

The Internet Explorer Event Object 447

Cross-Browser Event Object 449

Event Types 451

UI Events 452

Focus Events 458

Mouse and Wheel Events 459

Keyboard and Text Events 471

Composition Events 478

Mutation Events 479

HTML5 Events 482

Device Events 490

Touch and Gesture Events 494

Memory and Performance 498

Event Delegation 498

Removing Event Handlers 500

Simulating Events 502

DOM Event Simulation 502

Internet Explorer Event Simulation 508

Summary 509

Chapter 14: Scripting Forms 511

Form Basics 511

Submitting Forms 512

Resetting Forms 513

Form Fields 514

Scripting Text Boxes 520

Text Selection 521

Input Filtering 524

Automatic Tab Forward 528

HTML5 Constraint Validation API 530

Scripting Select Boxes 534

Options Selection 536

Adding Options 537

Removing Options 538

Moving and Reordering Options 539

Form Serialization 540

Rich Text Editing 542

Using contenteditable 543

Interacting with Rich Text 543

Rich Text Selections 547

Rich Text in Forms 549

Summary 549

Chapter 15: Graphics with Canvas 551

Basic Usage 551

The 2D Context 553

Fills and Strokes 553

Drawing Rectangles 553

Drawing Paths 556

Drawing Text 557

Transformations 559

Drawing Images 563

Shadows 564

Gradients 565

Patterns 567

Working with Image Data 567

Compositing 569

WebGL 571

Typed Arrays 571

The WebGL Context 576

Support 588

Summary 588

Chapter 16: Html5 Scripting 591

Cross-Document Messaging 591

Native Drag and Drop 593

Drag-and-Drop Events 593

Custom Drop Targets 594

The dataTransfer Object 595

DropEffect and eff ectAllowed 596

Draggability 597

Additional Members 598

Media Elements 598

Properties 599

Events 601

Custom Media Players 602

Codec Support Detection 603

The Audio Type 604

History State Management 605

Summary 606

Chapter 17: Error Handling and Debugging 607

Browser Error Reporting 607

Internet Explorer 608

Firefox 609

Safari 610

Opera 612

Chrome 613

Error Handling 614

The try-catch Statement 615

Throwing Errors 619

The error Event 622

Error-handling Strategies 623

Identify Where Errors Might Occur 623

Distinguishing between Fatal and Nonfatal Errors 628

Log Errors to the Server 629

Debugging Techniques 630

Logging Messages to a Console 631

Logging Messages to the Page 633

Throwing Errors 634

Common Internet Explorer Errors 635

Operation Aborted 635

Invalid Character 637

Member Not Found 637

Unknown Runtime Error 638

Syntax Error 638

The System Cannot Locate the Resource Specified 639

Summary 639

Chapter 18: Xml in Javascript 641

XML DOM Support in Browsers 641

DOM Level 2 Core 641

The DOMParser Type 642

The XMLSerializer Type 644

XML in Internet Explorer 8 and Earlier 644

Cross-Browser XML Processing 649

XPath Support in Browsers 651

DOM Level 3 XPath 651

XPath in Internet Explorer 656

Cross-Browser XPath 657

XSLT Support in Browsers 660

XSLT in Internet Explorer 660

The XSLTProcessor Type 665

Cross-Browser XSLT 667

Summary 668

Chapter 19: ECMAscript for Xml 671

E4X Types 671

The XML Type 672

The XMLList Type 673

The Namespace Type 674

The QName Type 675

General Usage 676

Accessing Attributes 678

Other Node Types 679

Querying 681

XML Construction and Manipulation 682

Parsing and Serialization Options 685

Namespaces 686

Other Changes 688

Enabling Full E4X 689

Summary 689

Chapter 20: JSON 691

Syntax 691

Simple Values 692

Objects 692

Arrays 693

Parsing and Serialization 694

The JSON Object 695

Serialization Options 696

Parsing Options 699

Summary 700

Chapter 21: AJAX and COMET 701

The XMLHttpRequest Object 702

XHR Usage 703

HTTP Headers 706

GET Requests 707

POST Requests 708

XMLHttpRequest Level 2 710

The FormData Type 710

Timeouts 711

The overrideMimeType() Method 711

Progress Events 712

The load Event 712

The progress Event 713

Cross-Origin Resource Sharing 714

CORS in Internet Explorer 714

CORS in Other Browsers 716

Prefl ighted Requests 717

Credentialed Requests 718

Cross-Browser CORS 718

Alternate Cross-Domain Techniques 719

Image Pings 719

Comet 721

Server-Sent Events 723

Web Sockets 725

SSE versus Web Sockets 727

Security 728

Summary 729

Chapter 22: Advanced Techniques 731

Advanced Functions 731

Safe Type Detection 731

Scope-Safe Constructors 733

Lazy Loading Functions 736

Function Binding 738

Function Currying 741

Tamper-Proof Objects 743

Nonextensible Objects 744

Sealed Objects 744

Frozen Objects 745

Advanced Timers 746

Repeating Timers 748

Yielding Processes 750

Function Throttling 752

Custom Events 755

Drag and Drop 758

Fixing Drag Functionality 760

Adding Custom Events 762

Summary 764

Chapter 23: Offline Applications and Client-Side Storage 765

Offline Detection 765

Application Cache 766

Data Storage 768

Cookies 768

Internet Explorer User Data 778

Web Storage 780

IndexedDB 786

Summary 799

Chapter 24: Best Practices 801

Maintainability 801

What is Maintainable Code? 802

Code Conventions 802

Loose Coupling 805

Programming Practices 809

Performance 814

Be Scope-Aware 814

Choose the Right Approach 816

Minimize Statement Count 821

Optimize DOM Interactions 824

Deployment 827

Build Process 827

Validation 829

Compression 830

Summary 833

Chapter 25: Emerging APIS 835

RequestAnimationFrame() 835

Early Animation Loops 836

Problems with Intervals 836

mozRequestAnimationFrame 837

webkitRequestAnimationFrame and msRequestAnimationFrame 838

Page Visibility API 839

Geolocation API 841

File API 843

The FileReader Type 844

Partial Reads 846

Object URLs 847

Drag-and-Drop File Reading 848

File Upload with XHR 849

Web Timing 851

Web Workers 852

Using a Worker 852

Worker Global Scope 853

Including Other Scripts 855

The Future of Web Workers 855

Summary 856

Appendix A: ECMAscript Harmony 857

General Changes 857

Constants 858

Block-Level and Other Scopes 858

Functions 859

Rest and Spread Arguments 859

Default Argument Values 860

Generators 861

Arrays and Other Structures 861

Iterators 862

Array Comprehensions 863

Destructuring Assignments 864

New Object Types 865

Proxy Objects 865

Proxy Functions 868

Map and Set 868

WeakMap 869

StructType 869

ArrayType 870

Classes 871

Private Members 872

Getters/Setters 872

Inheritance 873

Modules 874

External Modules 875

Appendix B: Strict Mode 877

Opting-in 877

Variables 878

Objects 878

Functions 879

eval() 880

eval and arguments 881

Coercion of this 882

Other Changes 882

Appendix C: Javascript Libraries 885

General Libraries 885

Yahoo! User Interface Library (YUI) 885

Prototype 886

The Dojo Toolkit 886

MooTools 886

jQuery 886

MochiKit 886

Underscore.js 887

Internet Applications 887

Backbone.js 887

Rico 887

qooxdoo 887

Animation and Eff ects 888

script.aculo.us 888

moo.fx 888

Lightbox 888

Cryptography 888

JavaScript MD5 889

JavaScrypt 889

Appendix D: Javascript Tools 891

Validators 891

JSLint 891

JSHint 892

JavaScript Lint 892

Minifi ers 892

JSMin 892

Dojo ShrinkSafe 892

YUI Compressor 893

Unit Testing 893

JsUnit 893

YUI Test 893

Dojo Object Harness (DOH) 894

qUnit 894

Documentation Generators 894

JsDoc Toolkit 894

YUI Doc 894

AjaxDoc 895

Secure Execution Environments 895

ADsafe 895

Caja 895

Index 897

Printer-Ready Version   Share This
With you wherever you go: pdf + ePub + kindle -- DRM-free