Pro JavaScript Design Patterns 1st Edition Ross Harmes - The ebook is available for quick download, easy access to content
Pro JavaScript Design Patterns 1st Edition Ross Harmes - The ebook is available for quick download, easy access to content
https://ebookfinal.com/download/pro-javascript-techniques-2nd-edition-
john-resig/
https://ebookfinal.com/download/scala-design-patterns-1st-edition-
nikolov/
https://ebookfinal.com/download/elemental-design-patterns-1st-edition-
jason-mcc-smith/
https://ebookfinal.com/download/head-first-design-patterns-1st-
edition-eric-freeman/
Java Design Patterns 1st Edition Mr. Devendra Singh
https://ebookfinal.com/download/java-design-patterns-1st-edition-mr-
devendra-singh/
https://ebookfinal.com/download/the-basics-of-permaculture-design-
ross-mars/
https://ebookfinal.com/download/c-3-0-design-patterns-1st-edition-
judith-bishop/
https://ebookfinal.com/download/advanced-actionscript-3-2nd-edition-
design-patterns-ben-smith/
https://ebookfinal.com/download/ontology-representation-design-
patterns-and-ontologies-that-make-sense-1st-edition-r-hoekstra/
Pro JavaScript Design Patterns 1st Edition Ross Harmes
Digital Instant Download
Author(s): Ross Harmes; Dustin Diaz
ISBN(s): 9781590599082, 159059908X
Edition: 1
File Details: PDF, 2.46 MB
Year: 2008
Language: english
CYAN YELLOW
MAGENTA BLACK
PANTONE 123 C
Pro
Web programming is becoming more complex and collaborative each day. A
new JavaScript™ library is born each week, and we are getting closer to the time
when web applications can seamlessly replace those found on our desktops. It
is no longer possible to design the behavior of your sites haphazardly without
thinking about long-term software maintainability.
JavaScript
The JavaScript language has matured. We have reached a point where soft-
ware development techniques once considered useful only in languages such
as Java and C++ are being applied to web programming. Therefore, we felt the
™
time has come for a book that explores object-oriented design principles and
applies them to the JavaScript language. The techniques needed to implement
patterns like factory, singleton, observer, composite, and facade in JavaScript
are easily understood, but they have not previously been discussed in depth in
a single book. We wanted to show programmers that JavaScript contains features
Design Patterns
on par with other high-level languages and is an object-oriented programming
language in its own right. In fact, we wrote the book that we ourselves have always
™
wanted to read.
In this book, we will teach you about commonly used software patterns for
designing the code that drives your websites and applications. You will learn
object-oriented JavaScript programming, starting with routine tasks and pro-
gressing to advanced techniques and patterns. We will help you create libraries
and APIs that can be used by others, as well as show you techniques that will
help you interact with other JavaScript programmers and work effectively in
large teams. Most of all, we will show you how powerful, expressive, and flexible
the JavaScript language can be.
US $44.99
Shelve in
Web development
User level:
9 781590 599082
Intermediate–Advanced
this print for content only—size & color not accurate spine = 0.693" 296 page count
908Xch00FM.qxd 11/16/07 1:05 PM Page i
™
Pro JavaScript
Design Patterns
Contents at a Glance
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
v
908Xch00FM.qxd 11/16/07 1:05 PM Page vi
908Xch00FM.qxd 11/16/07 1:05 PM Page vii
Contents
■CHAPTER 2 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
What Is an Interface? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Benefits of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Drawbacks of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
How Other Object-Oriented Languages Handle Interfaces . . . . . . . . . . . . . 12
Emulating an Interface in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Describing Interfaces with Comments . . . . . . . . . . . . . . . . . . . . . . . . . 14
Emulating Interfaces with Attribute Checking . . . . . . . . . . . . . . . . . . . 16
Emulating Interfaces with Duck Typing . . . . . . . . . . . . . . . . . . . . . . . . 17
The Interface Implementation for This Book . . . . . . . . . . . . . . . . . . . . . . . . . 18
The Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
When to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
How to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Example: Using the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Patterns That Rely on the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
vii
908Xch00FM.qxd 11/16/07 1:05 PM Page viii
viii ■CONTENTS
■CHAPTER 4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Why Do You Need Inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Prototype Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The extend Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Asymmetrical Reading and Writing of Inherited Members . . . . . . . . 46
The clone Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Comparing Classical and Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . 49
Inheritance and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Mixin Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Example: Edit-in-Place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Using Mixin Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
When Should Inheritance Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
■CONTENTS ix
■CHAPTER 6 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Structure of a Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Building a Chainable JavaScript Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Using Callbacks to Retrieve Data from Chained Methods . . . . . . . . . . . . . 89
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
x ■CONTENTS
■CONTENTS xi
xii ■CONTENTS
■CONTENTS xiii
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
f7670b088a34e6aa65a5685727db1ff4
908Xch00FM.qxd 11/16/07 1:05 PM Page xiv
908Xch00FM.qxd 11/16/07 1:05 PM Page xv
xv
908Xch00FM.qxd 11/16/07 1:05 PM Page xvi
908Xch00FM.qxd 11/16/07 1:05 PM Page xvii
■SIMON WILLISON is a consultant on client- and server-side web development and a cocreator
of the Django web framework. Simon’s interests include OpenID, unobtrusive JavaScript,
and rapid application development. Before going freelance, Simon worked on Yahoo!’s
Technology Development team, and prior to that at the Lawrence Journal-World, an award-
winning local newspaper in Kansas. Simon maintains a popular web development weblog
at http://simonwillison.net/.
xvii
908Xch00FM.qxd 11/16/07 1:05 PM Page xviii
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER VII.
A STRANGE FANCY.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com