没有合适的资源?快使用搜索试试~ 我知道了~
首页Learning JavaScript Design Patterns.pdf
Learning JavaScript Design Patterns.pdf

https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 2016年5月2日保存。
资源详情
资源评论
资源推荐

2016/5/2 Learning JavaScript Design Patterns
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 1/232
Learning JavaScript Design Patterns
A book by Addy Osmani
Volume 1.6.2
Tweet
Copyright © Addy Osmani 2015.
Learning JavaScript Design Patterns is released under a Creative Commons Attribution-
Noncommercial-No Derivative Works 3.0 unported license. It is available for purchase
via O'Reilly Media but will remain available for both free online and as a physical (or
eBook) purchase for readers wishing to support the project.

2016/5/2 Learning JavaScript Design Patterns
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 2/232
Preface
Design patterns are reusable solutions to commonly occurring problems in software
design. They are both exciting and a fascinating topic to explore in any programming
language.
One reason for this is that they help us build upon the combined experience of many
developers that came before us and ensure we structure our code in an optimized way,
meeting the needs of problems we're attempting to solve.
Design patterns also provide us a common vocabulary to describe solutions. This can be
significantly simpler than describing syntax and semantics when we're attempting to
convey a way of structuring a solution in code form to others.
In this book we will explore applying both classical and modern design patterns to the
JavaScript programming language.
Target Audience
This book is targeted at professional developers wishing to improve their knowledge of
design patterns and how they can be applied to the JavaScript programming language.
Some of the concepts covered (closures, prototypal inheritance) will assume a level of
basic prior knowledge and understanding. If you find yourself needing to read further
about these topics, a list of suggested titles is provided for convenience.
If you would like to learn how to write beautiful, structured and organized code, I
believe this is the book for you.
Acknowledgments
I will always be grateful for the talented technical reviewers who helped review and
improve this book, including those from the community at large. The knowledge and
enthusiasm they brought to the project was simply amazing. The official technical
reviewers tweets and blogs are also a regular source of both ideas and inspiration and I

2016/5/2 Learning JavaScript Design Patterns
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 3/232
wholeheartedly recommend checking them out.
Nicholas Zakas (http://nczonline.net, @slicknet)
Andrée Hansson (http://andreehansson.se, @peolanha)
Luke Smith (http://lucassmith.name, @ls_n)
Eric Ferraiuolo (http://ericf.me/, @ericf)
Peter Michaux (http://michaux.ca, @petermichaux)
Alex Sexton (http://alexsexton.com, @slexaxton)
I would also like to thank Rebecca Murphey (http://rmurphey.com, @rmurphey) for
providing the inspiration to write this book and more importantly, continue to make it
both available on GitHub and via O'Reilly.
Finally, I would like to thank my wonderful wife Ellie, for all of her support while I was
putting together this publication.
Credits
Whilst some of the patterns covered in this book were implemented based on personal
experience, many of them have been previously identified by the JavaScript community.
This work is as such the production of the combined experience of a number of
developers. Similar to Stoyan Stefanov's logical approach to preventing interruption of
the narrative with credits (in JavaScript Patterns), I have listed credits and suggested
reading for any content covered in the references section.
If any articles or links have been missed in the list of references, please accept my
heartfelt apologies. If you contact me I'll be sure to update them to include you on the
list.
Reading
Whilst this book is targeted at both beginners and intermediate developers, a basic
understanding of JavaScript fundamentals is assumed. Should you wish to learn more
about the language, I am happy to recommend the following titles:
JavaScript: The Definitive Guide by David Flanagan
Eloquent JavaScript by Marijn Haverbeke
JavaScript Patterns by Stoyan Stefanov

2016/5/2 Learning JavaScript Design Patterns
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 4/232
Writing Maintainable JavaScript by Nicholas Zakas
JavaScript: The Good Parts by Douglas Crockford
Table Of Contents
Introduction
What is a Pattern?
"Pattern"-ity Testing, Proto-Patterns & The Rule Of Three
The Structure Of A Design Pattern
Writing Design Patterns
Anti-Patterns
Categories Of Design Pattern
Summary Table Of Design Pattern Categorization
JavaScript Design Patterns
Constructor Pattern
Module Pattern
Revealing Module Pattern
Singleton Pattern
Observer Pattern
Mediator Pattern
Prototype Pattern
Command Pattern
Facade Pattern
Factory Pattern
Mixin Pattern
Decorator Pattern
Flyweight Pattern
JavaScript MV* Patterns
MVC Pattern
MVP Pattern
MVVM Pattern
Modern Modular JavaScript Design Patterns
AMD
CommonJS
ES Harmony
Design Patterns In jQuery
Composite Pattern

2016/5/2 Learning JavaScript Design Patterns
https://addyosmani.com/resources/essentialjsdesignpatterns/book/ 5/232
Adapter Pattern
Facade Pattern
Observer Pattern
Iterator Pattern
Lazy Initialization Pattern
Proxy Pattern
Builder Pattern
jQuery Plugin Design Patterns
JavaScript Namespacing Patterns
Conclusions
References
Introduction
One of the most important aspects of writing maintainable code is being able to notice
the recurring themes in that code and optimize them. This is an area where knowledge
of design patterns can prove invaluable.
In the first part of this book, we will explore the history and importance of design
patterns which can really be applied to any programming language. If you're already
sold on or are familiar with this history, feel free to skip to the chapter "What is a
Pattern?" to continue reading.
Design patterns can be traced back to the early work of an architect named Christopher
Alexander. He would often write publications about his experience in solving design
issues and how they related to buildings and towns. One day, it occurred to Alexander
that when used time and time again, certain design constructs lead to a desired optimal
effect.
In collaboration with Sara Ishikawa and Murray Silverstein, Alexander produced a
pattern language that would help empower anyone wishing to design and build at any
scale. This was published back in 1977 in a paper titled "A Pattern Language", which
was later released as a complete hardcover book.
Some 30 years ago, software engineers began to incorporate the principles Alexander
had written about into the first documentation about design patterns, which was to be a
剩余231页未读,继续阅读















安全验证
文档复制为VIP权益,开通VIP直接复制

评论3