Learning JavaScript Design Patterns - Addy Osmani

所需积分/C币:10 2015-10-27 15:31:58 2.42MB PDF
收藏 收藏 4

JavaScript开发进阶宝典。 The patterns we will be exploring in this section are the: • Creational Pattern • Constructor Pattern • Singleton Pattern • Module Pattern • Revealing Module Pattern • Observer Pattern • Mediator Pattern • Prototype Pattern • Command Pattern • Facade Pattern • Factory Pattern • Mi
Learning JavaScript Design Patterns by addy osmani Copyright o 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. Introduction 2. What is a pattern? We already use patterns everyday 3. Pattern'-ity Testing, Proto-Patterns& The rule of Three 4. The structure of A Design Pattern......,..........,....9 5. Writing Design Patterns 6. Anti-Patterns 13 7. Categories Of Design Pattern 15 Creational Design Patterns Structural Design Patterns 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 The Module pattern 27 Modules 27 Object literals The Module pattern 29 The Revealing module Pattern 36 The observer pattern 37 Advantages 38 Disadvantages 39 Implementations 39 The Mediator Pattern Advantages disadvantages 50 Mediator Vs Observer 51 Mediator vs Facade 51 The prototype pattern 52 The Command pattern 54 The Facade pattern 56 The factory Pattern When To Use The Factory Pattern 59 When not to Use The Factory Pattern 59 The mixin pattern The decorator pattern 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 Interfa 65 This variation of decorators and abstract decorators Implementing decorators with jQuery Pros and cons of the pattern 70 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 76 Example 2: Using the flyweight for Performance gains 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 88 Summary MVP Models. Views Presenters 89 MVP or mvc? MVC, MVP and Backbone. js MVVM 92 History 92 Model 94 View Model 96 Recap The View and the View Model Recap: The View Model and the Model Pros and cons advantages 98 Disadvantages MVVM With Looser Data-Bindings MVCVS. MVPVS MVVM 103 Backbone. js Vs KnockoutS 103 Namespacing Patterns 104 What is namespacing 104 Advanced namespacing patterns 105 Automating nested namespacing 105 Dependency declaration pattern 107 Deep object extension 108 Namespacing Fundamentals 110 1. Single global variables 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〔ore∴…….121 Module pattern 121 Lazy initialization 122 The Composite Pattern 123 Table of Contents v The Adapter Pattern The Facade pattern 124 The observer pattern 125 The iterator pattern 126 The Strategy Pattern 127 The proxy pattern 127 The Builder pattern 128 The Prototype Pattern 128 13. Modern Modular JavaScript Design Patterns.... ...... ...... 131 he 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 Getting Started 141 AMd & CommonJS Competing, But equally Valid Standards 144 Basic AMd Hybrid Format ohn Hann 145 AMD/ CommonJS 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 154 A Lightweight Start 155 Further Reading 156 Complete"Widget Factory 157 Further reading 159 Namespacing And Nested Namespacing 159 ⅵ i Table of Contents Further readins g 161 Custom Events For Pub/Sub( With The Widget factory) 161 Further reading 162 Prototypal Inheritance With The DOM-To-Object Bridge Pattern 162 Further reading 164 jQuery UI Widget Factory Bridge 164 Further reading 166 jQuery mobile Widgets With The Widget factor 167 Require jS and The jQuery UI Widget Factory 169 Further reading 172 Globally and Per-Call Overridable Options (Best Options Pattern 172 eading 174 A Highly Configurable And Mutable Plugin 174 Further reading 176 UMD: AMD And Common JS-Compatible Modules For Plugins Further reading 179 What Makes a Good Plugin Beyond Patterns? 179 15.〔 onclusions ,,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 anguage 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
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    qq_39618048 评论不了吗?
    关注 私信 TA的资源
    Learning JavaScript Design Patterns - Addy Osmani 10积分/C币 立即下载
    Learning JavaScript Design Patterns - Addy Osmani第1页
    Learning JavaScript Design Patterns - Addy Osmani第2页
    Learning JavaScript Design Patterns - Addy Osmani第3页
    Learning JavaScript Design Patterns - Addy Osmani第4页
    Learning JavaScript Design Patterns - Addy Osmani第5页
    Learning JavaScript Design Patterns - Addy Osmani第6页
    Learning JavaScript Design Patterns - Addy Osmani第7页
    Learning JavaScript Design Patterns - Addy Osmani第8页
    Learning JavaScript Design Patterns - Addy Osmani第9页
    Learning JavaScript Design Patterns - Addy Osmani第10页
    Learning JavaScript Design Patterns - Addy Osmani第11页
    Learning JavaScript Design Patterns - Addy Osmani第12页
    Learning JavaScript Design Patterns - Addy Osmani第13页
    Learning JavaScript Design Patterns - Addy Osmani第14页
    Learning JavaScript Design Patterns - Addy Osmani第15页
    Learning JavaScript Design Patterns - Addy Osmani第16页
    Learning JavaScript Design Patterns - Addy Osmani第17页
    Learning JavaScript Design Patterns - Addy Osmani第18页
    Learning JavaScript Design Patterns - Addy Osmani第19页
    Learning JavaScript Design Patterns - Addy Osmani第20页


    10积分/C币 立即下载 >