Pro JavaScript design patterns : [the essentials of object-oriented JavaScript programming
معرفی کتاب «Pro JavaScript design patterns : [the essentials of object-oriented JavaScript programming» نوشتهٔ Dustin Diaz, Ross Harmes، منتشرشده توسط نشر Apress ; Distributed to the Book trade worldwide by Springer-Verlag New York در سال 2007. این کتاب در 5 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Pro JavaScript design patterns : [the essentials of object-oriented JavaScript programming» در دستهٔ بدون دستهبندی قرار دارد.
As a web developer, you’ll already know that JavaScript is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked—JavaScript is capable of full object–oriented capabilities, and by applying OOP principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team. With Pro JavaScript Design Patterns , you’ll start with the basics of object–oriented programming in JavaScript applicable to design patterns, including making JavaScript more expressive, inheritance, encapsulation, information hiding, and more. With that covered, you can kick–start your JavaScript development in the second part of the book, where you’ll find detail on how to implement and take advantage of several design patterns in JavaScript, including composites, decorators, façades, adapters, and many more. Each chapter is packed with real–world examples of how the design patterns are best used and expert advice on writing better code, as well as what to watch out for. Along the way you’ll discover how to create your own libraries and APIs for even more efficient coding. Master the basics of object–oriented programming in JavaScript, as they apply to design patterns. Apply design patterns to your kick–start your JavaScript development. Work through several real–world examples. What you’ll learn How to apply object–oriented programming techniques in JavaScript How to take advantage of inheritance, interfaces, and encapsulation and information hiding to kick–start your JavaScript development How to implement several design patterns in your JavaScript projects, including factory, façade, bridge, composite, adapter, decorator, flyweight, proxy, command, observer, and chain of responsibility How to make your code easier to manage in a team environment, as well as on your own How to create your own libraries and APIs Who this book is for This book will be an invaluable learning tool for any experienced JavaScript developer. Table of Contents Expressive JavaScript Interfaces Encapsulation and Information Hiding Inheritance The Singleton Pattern Chaining The Factory Pattern The Bridge Pattern The Composite Pattern The Facade Pattern The Adapter Pattern The Decorator Pattern The Flyweight Pattern The Proxy Pattern The Observer Pattern The Command Pattern The Chain of Responsibility Pattern Prelims 1 Contents at a Glance 7 Contents 9 About the Authors 17 About the Technical Reviewer 19 Acknowledgments 21 Introduction 23 Who This Book Is For 23 How This Book Is Structured 24 Part 1 24 Chapter 1: Expressive JavaScript 24 Chapter 2: Interfaces 24 Chapter 3: Encapsulation and Information Hiding 25 Chapter 4: Inheritance 25 Chapter 5: The Singleton Pattern 25 Chapter 6: Chaining 25 Part 2 25 Chapter 7: The Factory Pattern 25 Chapter 8: The Bridge Pattern 25 Chapter 9: The Composite Pattern 25 Chapter 10: The Facade Pattern 26 Chapter 11: The Adapter Pattern 26 Chapter 12: The Decorator Pattern 26 Chapter 13: The Flyweight Pattern 26 Chapter 14: The Proxy Pattern 26 Chapter 15: The Observer Pattern 26 Chapter 16: The Command Pattern 27 Chapter 17: The Chain of Responsibility Pattern 27 Prerequisites 27 Downloading the Code 28 Contacting the Authors 28 Expressive JavaScript 31 The Flexibility of JavaScript 31 A Loosely Typed Language 34 Functions As First-Class Objects 34 The Mutability of Objects 36 Inheritance 37 Design Patterns in JavaScript 37 Summary 38 Interfaces 39 What Is an Interface? 39 Benefits of Using Interfaces 39 Drawbacks of Using Interfaces 40 How Other Object-Oriented Languages Handle Interfaces 40 Emulating an Interface in JavaScript 42 Describing Interfaces with Comments 42 Emulating Interfaces with Attribute Checking 44 Emulating Interfaces with Duck Typing 45 The Interface Implementation for This Book 46 The Interface Class 47 When to Use the Interface Class 48 How to Use the Interface Class 48 Example: Using the Interface Class 49 Patterns That Rely on the Interface 51 Summary 51 Encapsulation and Information Hiding 53 The Information Hiding Principle 53 Encapsulation vs. Information Hiding 54 The Role of the Interface 54 Basic Patterns 54 Fully Exposed Object 55 Private Methods Using a Naming Convention 58 Scope, Nested Functions, and Closures 60 Private Members Through Closures 61 More Advanced Patterns 63 Static Methods and Attributes 63 Constants 65 Singletons and Object Factories 66 Benefits of Using Encapsulation 67 Drawbacks to Using Encapsulation 67 Summary 68 Inheritance 69 Why Do You Need Inheritance? 69 Classical Inheritance 70 The Prototype Chain 70 The extend Function 71 Prototypal Inheritance 73 Asymmetrical Reading and Writing of Inherited Members 74 The clone Function 76 Comparing Classical and Prototypal Inheritance 77 Inheritance and Encapsulation 77 Mixin Classes 78 Example: Edit-in-Place 80 Using Classical Inheritance 80 Using Prototypal Inheritance 83 Using Mixin Classes 87 When Should Inheritance Be Used? 90 Summary 91 The Singleton Pattern 93 The Basic Structure of the Singleton 93 Namespacing 94 A Singleton As a Wrapper for Page-Specific Code 96 A Singleton with Private Members 98 Using the Underscore Notation 98 Using Closures 99 Comparing the Two Techniques 102 Lazy Instantiation 103 Branching 106 Example: Creating XHR Objects with Branching 107 When Should the Singleton Pattern Be Used? 109 Benefits of the Singleton Pattern 109 Drawbacks of the Singleton Pattern 110 Summary 110 Chaining 111 The Structure of a Chain 112 Building a Chainable JavaScript Library 114 Using Callbacks to Retrieve Data from Chained Methods 117 Summary 118 The Factory Pattern 121 The Simple Factory 121 The Factory Pattern 124 When Should the Factory Pattern Be Used? 127 Dynamic Implementations 127 Combining Setup Costs 127 Abstracting Many Small Objects into One Large Object 127 Example: XHR Factory 127 Specialized Connection Objects 129 Choosing Connection Objects at Run-Time 131 Example: RSS Reader 132 Benefits of the Factory Pattern 135 Drawbacks of the Factory Pattern 136 Summary 136 The Bridge Pattern 137 Example: Event Listeners 137 Other Examples of Bridges 138 Bridging Multiple Classes Together 139 Example: Building an XHR Connection Queue 139 Including the Core Utilities 140 Including an Observer System 142 Developing the Queue Skeleton 142 Implementing the Queue 144 Where Have Bridges Been Used? 150 When Should the Bridge Pattern Be Used? 150 Benefits of the Bridge Pattern 151 Drawbacks of the Bridge Pattern 151 Summary 151 The Composite Pattern 153 The Structure of the Composite 154 Using the Composite Pattern 154 Example: Form Validation 155 Putting It All Together 161 Adding Operations to FormItem 161 Adding Classes to the Hierarchy 161 Adding More Operations 164 Example: Image Gallery 164 Benefits of the Composite Pattern 167 Drawbacks of the Composite Pattern 167 Summary 168 The Facade Pattern 169 Some Facade Functions You Probably Already Know About 169 JavaScript Libraries As Facades 170 Facades As Convenient Methods 171 Example: Setting Styles on HTML Elements 172 Example: Creating an Event Utility 174 General Steps for Implementing the Facade Pattern 175 When Should the Facade Pattern Be Used? 176 Benefits of the Facade Pattern 176 Drawbacks of the Facade Pattern 176 Summary 176 The Adapter Pattern 177 Characteristics of an Adapter 177 Adapting Existing Implementations 178 Example: Adapting One Library to Another 178 Example: Adapting an Email API 180 Wrapping the Webmail API in an Adapter 185 Migrating from fooMail to dedMail 185 When Should the Adapter Pattern Be Used? 186 Benefits of the Adapter Pattern 186 Drawbacks of the Adapter Pattern 186 Summary 186 The Decorator Pattern 187 The Structure of the Decorator 187 The Role of the Interface in the Decorator Pattern 191 The Decorator Pattern vs. the Composite Pattern 191 In What Ways Can a Decorator Modify Its Component? 192 Adding Behavior After a Method 192 Adding Behavior Before a Method 193 Replacing a Method 194 Adding New Methods 195 The Role of the Factory 197 Function Decorators 200 When Should the Decorator Pattern Be Used? 201 Example: Method Profiler 201 Benefits of the Decorator Pattern 204 Drawbacks of the Decorator Pattern 204 Summary 205 The Flyweight Pattern 207 The Structure of the Flyweight 207 Example: Car Registrations 207 Intrinsic and Extrinsic State 208 Instantiation Using a Factory 209 Extrinsic State Encapsulated in a Manager 210 Managing Extrinsic State 211 Example: Web Calendar 211 Converting the Day Objects to Flyweights 213 Where Do You Store the Extrinsic Data? 214 Example: Tooltip Objects 214 The Unoptimized Tooltip Class 215 Tooltip As a Flyweight 216 Storing Instances for Later Reuse 218 When Should the Flyweight Pattern Be Used? 220 General Steps for Implementing the Flyweight Pattern 221 Benefits of the Flyweight Pattern 221 Drawbacks of the Flyweight Pattern 222 Summary 222 The Proxy Pattern 225 The Structure of the Proxy 225 How Does the Proxy Control Access to Its Real Subject? 225 Virtual Proxy, Remote Proxy, and Protection Proxy 228 The Proxy Pattern vs. the Decorator Pattern 229 When Should the Proxy Be Used? 229 Example: Page Statistics 229 General Pattern for Wrapping a Web Service 233 Example: Directory Lookup 234 General Pattern for Creating a Virtual Proxy 238 Benefits of the Proxy Pattern 241 Drawbacks of the Proxy Pattern 241 Summary 242 The Observer Pattern 243 Example: Newspaper Delivery 243 Push vs. Pull 244 Pattern in Practice 244 Building an Observer API 246 Delivery Method 247 Subscribe 247 Unsubscribe 248 Observers in Real Life 248 Example: Animation 249 Event Listeners Are Also Observers 250 When Should the Observer Pattern Be Used? 251 Benefits of the Observer Pattern 251 Drawbacks of the Observer Pattern 251 Summary 251 The Command Pattern 253 The Structure of the Command 253 Creating Commands with Closures 255 The Client, the Invoker, and the Receiver 255 Using Interfaces with the Command Pattern 256 Types of Command Objects 256 Example: Menu Items 258 The Menu Composites 259 The Command Class 261 Putting It All Together 262 Adding More Menu Items Later On 263 Example: Undo and Logging 263 Implementing Undo with Nonreversible Actions By Logging Commands 267 Logging Commands for Crash Recovery 270 When to Use the Command Pattern 270 Benefits of the Command Pattern 271 Drawbacks of the Command Pattern 271 Summary 272 The Chain of Responsibility Pattern 273 The Structure of the Chain of Responsibility 273 Passing on Requests 279 Implementing a Chain of Responsibility in an Existing Hierarchy 282 Event Delegation 283 When Should the Chain of Responsibility Pattern Be Used? 283 Example: Image Gallery Revisited 284 Using the Chain of Responsibility to Make Composites More Efficient 285 Adding Tags to Photos 286 Benefits of the Chain of Responsibility Pattern 289 Drawbacks of the Chain of Responsibility Pattern 290 Summary 290 Index 291 As a web developer, you'll already know that JavaScript is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlockedJavaScript is capable of full objectoriented capabilities, and by applyingobject-oriented principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team. With Pro JavaScript Design Patterns, you'll start with the basics of objectoriented programming in JavaScript applicable to design patterns, including making JavaScript more expressive, inheritance, encapsulation, information hiding, and more. With that covered, you can kickstart your JavaScript development in the second part of the book, where you'll find detail on how to implement and take advantage of several design patterns in JavaScript, including composites, decorators, facades, adapters, and many more. Each chapter is packed with realworld examples of how the design patterns are best used and expert advice on writing better code, as well as what to watch out for. Along the way you'll discover how to create your own libraries and APIs for even more efficient coding.Master the basics of objectoriented programming in JavaScript, as they apply to design patterns Apply design patterns to your kickstart your JavaScript development Work through several realworld examples What you'll learn How to apply objectoriented programming techniques in JavaScript How to take advantage of inheritance, interfaces, and encapsulation and information hiding to kickstart your JavaScript development How to implement several design patterns in your JavaScript projects, including factory, facade, bridge, composite, adapter, decorator, flyweight, proxy, command, observer, and chain of responsibility How to make your code easier to manage in a team environment, as well as on your own How to create your own libraries and APIs Who this book is for This book will be an invaluable learning tool for any experienced JavaScript developer. Table of Contents Expressive JavaScript Interfaces Encapsulation and Information Hiding Inheritance The Singleton Pattern Chaining The Factory Pattern The Bridge Pattern The Composite Pattern The Facade Pattern The Adapter Pattern The Decorator Pattern The Flyweight Pattern The Proxy Pattern The Observer Pattern The Command Pattern The Chain of Responsibility Pattern As a web developer, you’ll already know that JavaScript is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked—JavaScript is capable of full object–oriented capabilities, and by applying OOP principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team. With __Pro JavaScript Design Patterns__, you’ll start with the basics of object–oriented programming in JavaScript applicable to design patterns, including making JavaScript more expressive, inheritance, encapsulation, information hiding, and more. With that covered, you can kick–start your JavaScript development in the second part of the book, where you’ll find detail on how to implement and take advantage of several design patterns in JavaScript, including composites, decorators, façades, adapters, and many more. Each chapter is packed with real–world examples of how the design patterns are best used and expert advice on writing better code, as well as what to watch out for. Along the way you’ll discover how to create your own libraries and APIs for even more efficient coding. * Master the basics of object–oriented programming in JavaScript, as they apply to design patterns. * Apply design patterns to your kick–start your JavaScript development. * Work through several real–world examples. ## What you’ll learn ## Who this book is for This book will be an invaluable learning tool for any experienced JavaScript developer. ## Table of Contents As a web developer, you'll already know that JavaScript is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked--JavaScript is capable of full object-oriented capabilities, and by applying object-oriented principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team. With Pro JavaScript Design Patterns, you'll start with the basics of object-oriented programming in JavaScript applicable to design patterns, including making JavaScript more expressive, inheritance, encapsulation, information hiding, and more. With that covered, you can kick-start your JavaScript development in the second part of the book, where you'll find detail on how to implement and take advantage of several design patterns in JavaScript, including composites, decorators, façades, adapters, and many more. Each chapter is packed with real-world examples of how the design patterns are best used and expert advice on writing better code, as well as what to watch out for. Along the way you'll discover how to create your own libraries and APIs for even more efficient coding. Master the basics of object-oriented programming in JavaScript, as they apply to design patterns Apply design patterns to your kick-start your JavaScript development Work through several real-world examples As A Web Developer, You'll Already Know That Javascript Is A Powerful Language, Allowing You To Add An Impressive Array Of Dynamic Functionality To Otherwise Static Web Sites. But There Is More Power Waiting To Be Unlocked-- Javascript Is Capable Of Full Object-oriented Capabilities, And By Applying Oop Principles, Best Practices, And Design Patterns To Your Code, You Can Make It More Powerful, More Efficient, And Easier To Work With Alone Or As Part Of A Team. With Pro Javascript Design Patterns, You'll Start With The Basics Of Object-oriented Programming In Javascript Applicable To Design Patterns, Including Making Javascript More Expressive, Inheritance, Encapsulation, Information Hiding, And More. Pt. 1. Object-oriented Javascript -- Ch. 1. Expressive Javascript -- Ch. 2. Interfaces -- Ch. 3. Encapsulation And Information Hiding -- Ch. 4. Inheritance -- Ch. 5. The Singleton Pattern -- Ch. 6. Chaining -- Pt. 2. Design Patterns -- Ch. 7. The Factory Pattern -- Ch. 8. The Bridge Pattern -- Ch. 9. The Composite Pattern -- Ch. 10. The Facade Pattern -- Ch. 11. The Adapter Pattern -- Ch. 12. The Decorator Pattern -- Ch. 13. The Flyweight Pattern -- Ch. 14. The Proxy Pattern -- Ch. 15. The Observer Pattern -- Ch. 16. The Command Pattern -- Ch. 17. The Chain Of Responsibility Pattern. Ross Harmes And Dustin Diaz. Includes Index. With Pro JavaScript Design Patterns, you’ll start with the basics of object-oriented programming in JavaScript applicable to design patterns, including making JavaScript more expressive, inheritance, encapsulation, information hiding, and more. The book then details how to implement and take advantage of several design patterns in JavaScript. Each chapter is packed with real-world examples of how the design patterns are best used and expert advice on writing better code, as well as what to watch out for. Along the way you’ll discover how to create your own libraries and APIs for even more efficient coding.
دانلود کتاب Pro JavaScript design patterns : [the essentials of object-oriented JavaScript programming