Learning JavaScript Design Patterns - Addy Osmani.pdf

所需积分/C币:10 2017-09-27 08:11:48 2.3MB PDF
收藏 收藏 1

With Learning JavaScript Design Patterns, you’ll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to keep your code efficient, more manageable, and up-to-date with the latest best practices, this book
Learning javascript design Patterns by addy osmani Copyright@ 2012 Addy Osmani. All rights reserved Revision History for the 2012-05-01 Early release revision 1 Seehttp:/oreilly.com/catalog/errata.csp?isbn=9781449331818forreleasedetails ISBN:978-1-449-33181-8 1335906805 Table of contents Preface 1. Introducti 2. What is a pattern? We already use patterns everyday 3. Pattern'-ity Testing, Proto-Patterns The Rule of Three The structure of A Design Pattern 5. Writing Design Patterns 6. Anti-Patterns 7.〔 ategories0 f Design Pattern… 15 Creational Design Patterns Structural design p g Behavioral Design Patterns 16 8. Design Pattern Categorization a brief note on classes 17 9. Javascript design Patterns 21 The Creational pattern 22 The Constructor pattern Basic constructors 23 Constructors With Prototypes 24 The Singleton Pattern 24 The Module pattern 27 Object literals The Module pattern 29 The Revealing module Pattern 36 The Observer pattern advantages Disadvantages 39 Implementations 39 The Mediator Pattern 49 advantages disadvantages 50 Mediator Vs observer 51 Mediator vs Facade 51 The Prototype Pattern The Command pattern 54 The Facade pattern 56 The Factory Pattern When To Use The Factory Pattern 9 When not to use the factory Pattern 59 The mixin pattern 60 The decorator pattern 61 1bclassin g 61 Decorators 63 Example 1: Basic decoration of existing object constructors with new functionality 63 Example 2: Simply decorate objects with multiple decorators 64 Pseudo-classical decorators 65 Interfaces 65 This variation of decorators and abstract decorators mplementing decorators with jQuery 69 Pros and cons of the pattern 10. Flyweight Flyweight and the data layer 72 Converting code to use the Flyweight pattern A Basic Factory Managing the extrinsic states 74 The flyweight pattern and the dom 76 Example 1: Centralized event handling ng 76 Example 2: USing the Flyweight for Performance Gains 77 11. MV* Patterns ,79 MVC 79 Smalltalk-80 MVC 79 iv Table of Contents MVC For JavaScript Developers Models Views 82 Controllers Controllers in another library( Spine. js)vs Backbone. js What does mvc give us? 87 Delving deeper g 88 Summary MVP Models,Ⅴiews∝ Presenters 89 MVP or mvc? MVC, MVP and Backbone. js MVVM 92 Histo 92 Model View 94 View Mode 96 Recap: The view and the view Model Recap: The View Model and the Model Pros and Cons 98 Advantages 98 Disadvantages MVVM With Looser Data-Bindings MVCVS MVP VS MVVM 103 Backbone. js Vs KnockoutS 103 Namespacing Patterns 104 What is namespacing? 104 Advanced namespacing patterns 105 Automating nested namespacing 105 ependency declaration pattern 107 Deep object extension 108 Namespacing Fundamentals 110 1. Single global variables 111 2. Prefix namespacing 3. Object literal notation 112 4. Nested namespacing 114 5. Immediately-invoked Function Expressions(IIFE)s 115 6. Namespace injection 117 12. Design Patterns in jQuery core ,,,,121 Module pattern 121 Lazy initialization 122 The Composite Pattern 123 Table of contents The Adapter pattern 123 The Facade pattern 124 The Observer pattern 125 The iterator pattern 126 The Strategy Pattern 127 The Proxy Pattern 127 The Builder pattern 128 he Prototype Pattern 128 13. Modern Modular JavaScript Design Patterns ................ 131 The Importance Of Decoupling Your Application 131 A Note On Script loaders 132 AMD 132 A Format For Writing Modular JavaScript In The Browser 132 Getting Started With Modules 133 AMD Modules with dojo 137 AMD Module Design Patterns (dojo 138 AMD Modules With jQuery 139 AMD Conclusions 141 Common s 141 A Module Format Optimized for the server 141 tting starte 141 Basic aMd Hybrid Format (ohn Hann/y Valid Standards aMd & common jS Competing But equal 144 145 AMD/Common JS Universal Module Definition(Variation 2, UMDjs) 145 Extensible UMD Plugins With(Variation by myself and Thomas Davis). 146 ES Harmony 148 Modules of the future 148 Modules with imports and exports 148 Modules loaded from remote sources 149 Module loader api 150 CommonJS-like Modules For The Server 150 Classes With Constructors Getters Setters 150 Conclusions And Further reading a review 152 14. Bonus: jQuery Plugin Design Patterns∴….153 Patterns 154 Note 154 A Lightweight Start 155 Further reading 156 “ Complete” Widget Factory 157 Further reading 159 Namespacing And Nested Namespacing 159 vi Table of Contents Further reading 161 Custom Events For Pub/Sub(with The Widget factory) 161 Further reading 162 Prototypal Inheritance With The DOM-To-Object Bridge Pattern 162 er Reading 164 Query UI Widget Factory Bridge 164 Further reading 166 jQuery Mobile widgets With The widget factory 167 Requires and The jQuery UI Widget Factory 169 Further reading 172 Globally and Per-Call Overridable Options(Best Options Pattern 172 Further Reading 174 A Highly Configurable And Mutable Plugin 174 Further reading 176 UMD: AMD And CommonJS-Compatible Modules For Plugins Further reading 179 What Makes a good Plugin Beyond Patterns 179 15. Conclusions∴ ,,183 16. References ∴185 Table of contents|ⅶi 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 guage 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 were 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 lan guage 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 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 re

试读 127P Learning JavaScript Design Patterns - Addy Osmani.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    jeff_liugx 不知有用没有啊
    关注 私信 TA的资源
    Learning JavaScript Design Patterns - Addy Osmani.pdf 10积分/C币 立即下载
    Learning JavaScript Design Patterns - Addy Osmani.pdf第1页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第2页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第3页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第4页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第5页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第6页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第7页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第8页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第9页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第10页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第11页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第12页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第13页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第14页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第15页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第16页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第17页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第18页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第19页
    Learning JavaScript Design Patterns - Addy Osmani.pdf第20页


    10积分/C币 立即下载 >