Learning_JavaScript_Design_Patterns_2nd_Edition.pdf

(3336 KB) Pobierz
nd
co ion
Se dit
E
Learning
JavaScript
Design Patterns
A JavaScript and
React Developer
'
s Guide
Addy Osmani
Learning JavaScript Design Patterns
Do you want to write beautiful, structured, and maintainable
JavaScript by applying modern design patterns to the
language? Do you want clean, efficient, manageable
code? Want to stay up-to-date with the latest best
practices? If so, the updated second edition of
Learning
JavaScript Design Patterns
is the ideal place to start.
Author Addy Osmani shows you how to apply modern
design patterns— including modules, mixins, observers,
and mediators—to JavaScript and React. You’ll learn about
performance and rendering patterns such as server-side
rendering and Islands architecture. You’ll also learn how
architectural patterns like MVC, MVP, and MVVM are useful
from the perspective of a modern web application developer.
This book explores:
“Addy’s book is a
pragmatic approach to
fundamental concepts
that are useful across
myriad uses. JavaScript
Design Patterns are
intrinsic to developers
applying systems thinking
to their own work. Any
developer reading this
book will see incredible
returns on the time
investment reading it.”
Director of Engineering at Google
—Sarah Drasner
Architectural patterns for structuring your components
and apps
More than 20 design patterns in JavaScript and
React, applicable for developers at any level
creational, structural, and behavioral
dynamic imports and code-splitting
Different pattern categories including
Essential performance patterns including
Rendering patterns such as server-side rendering,
hydration, Islands architecture, and more
Additionally, you’ll explore modern JavaScript syntax like
JavaScript modules, React patterns like Hooks, higher-order
components (HOCs), and more, to stay ahead in the
ever-evolving world of web development.
“Addy Osmani strikes
again, and he has
delivered a much
appreciated update
to his already classic
book on design patterns
in JavaScript.”
—Stoyan Stefanov
WebPageTest.org engineer and
author of
JavaScript Patterns
Addy Osmani
is an engineering
leader for Google, where he leads
the Chrome developer experience
teams, helping to keep the web
fast and delightful to build upon.
WEB DEVELOPMENT
US $65.99 CAN $82.99
ISBN: 978-1-098-13987-2
Twitter: @oreillymedia
linkedin.com/company/oreilly-media
youtube.com/oreillymedia
SECOND EDITION
A JavaScript and React Developer’s Guide
Learning JavaScript
Design Patterns
Addy Osmani
Beijing
Boston Farnham Sebastopol
Tokyo
Learning JavaScript Design Patterns
by Addy Osmani
Copyright © 2023 Adnan Osmani. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://oreilly.com). For more information, contact our corporate/institu‐
tional sales department: 800-998-9938 or
corporate@oreilly.com.
Acquisitions Editor:
Amanda Quinn
Development Editor:
Michele Cronin
Production Editor:
Clare Laylock
Copyeditor:
Stephanie English
Proofreader:
Rising Sun Technologies
August 2012:
April 2023:
First Edition
Second Edition
Indexer:
Sue Klefstad
Interior Designer:
David Futato
Cover Designer:
Karen Montgomery
Illustrator:
Kate Dullea
Revision History for the Second Edition
2023-04-28:
First Release
See
http://oreilly.com/catalog/errata.csp?isbn=9781098139872
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Learning JavaScript Design Patterns,
the cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
The views expressed in this work are those of the author and do not represent the publisher’s views.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-098-13987-2
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1.
Introduction to Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
History of Design Patterns
What Is a Pattern?
An Everyday Use Case for Design Patterns
Summary
What Are Proto-Patterns?
The “Pattern” Tests
Rule of Three
Summary
2
2
4
5
7
8
9
9
2.
“Pattern”-ity Testing, Proto-Patterns, and the Rule of Three. . . . . . . . . . . . . . . . . . . . . . . 7
3.
Structuring and Writing Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
The Structure of a Design Pattern
Well-Written Patterns
Writing a Pattern
Summary
What Are Anti-Patterns?
Anti-Patterns in JavaScript
Summary
11
12
13
14
15
16
17
19
20
22
iii
4.
Anti-Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.
Modern JavaScript Syntax and Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
The Importance of Decoupling Applications
Modules with Imports and Exports
Module Objects
Zgłoś jeśli naruszono regulamin