售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
jQuery Design Patterns
Table of Contents
jQuery Design Patterns
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. A Refresher on jQuery and the Composite Pattern
jQuery and DOM scripting
Manipulating the DOM using jQuery
Method Chaining and Fluent Interfaces
The Composite Pattern
How the Composite Pattern is used by jQuery
Comparing the benefits over the plain DOM API
Using the Composite Pattern to develop applications
A sample use case
The Composite Collection Implementation
An example execution
Alternative implementations
The Iterator Pattern
How the Iterator Pattern is used by jQuery
How it pairs with the Composite Pattern
Where can it be used
Summary
2. The Observer Pattern
Introducing the Observer Pattern
How it is used by jQuery
The jQuery on method
The document-ready observer
Demonstrate a sample use case
How it is compared with event attributes
Avoid memory leaks
Introducing the Delegated Event Observer Pattern
How it simplifies our code
Compare the memory usage benefits
Summary
3. The Publish/Subscribe Pattern
Introducing the Publish/Subscribe Pattern
How it differs from the Observer Pattern
How it is adopted by jQuery
Custom events in jQuery
Implementing a Pub/Sub scheme using custom events
Demonstrating a sample use case
Using Pub/Sub on the dashboard example
Extending the implementation
Using any object as a broker
Using custom event namespacing
Summary
4. Divide and Conquer with the Module Pattern
Modules and Namespaces
Encapsulating internal parts of an implementation
Avoiding global variables with Namespaces
The benefits of these patterns
The wide acceptance
The Object Literal Pattern
The Module Pattern
The IIFE building block
The simple IIFE Module Pattern
How it is used by jQuery
The Namespace Parameter Module variant
The IIFE-contained Module variant
The Revealing Module Pattern
Using ES5 Strict Mode
Introducing ES6 Modules
Using Modules in jQuery applications
The main dashboard module
The categories module
The informationBox module
The counter module
Overview of the implementation
Summary
5. The Facade Pattern
Introducing the Facade Pattern
The benefits of this pattern
How it is adopted by jQuery
The jQuery DOM Traversal API
The property access and manipulation API
Using Facades in our applications
Summary
6. The Builder and Factory Patterns
Introducing the Factory Pattern
How it is adopted by jQuery
Using Factories in our applications
Introducing the Builder Pattern
How it is adopted by jQuery's API
How it is used by jQuery internally
How to use it in our applications
Summary
7. Asynchronous Control Flow Patterns
Programming with callbacks
Using simple callbacks in JavaScript
Setting callbacks as object properties
Using callbacks in jQuery applications
Writing methods that accept callbacks
Orchestrating callbacks
Queuing in order execution
Avoiding the Callback Hell anti-pattern
Running concurrently
Introducing the concept of Promises
Using Promises
Using the jQuery Promise API
Using Promises/A+
Comparing jQuery and A+ Promises
Advanced concepts
Chaining Promises
Handling thrown errors
Joining Promises
How jQuery uses Promises
Transforming Promises to other types
Transforming to Promises/A+
Transforming to jQuery Promises
Summarizing the benefits of Promises
Summary
8. Mock Object Pattern
Introducing the Mock Object Pattern
Using Mock Objects in jQuery applications
Defining the actual service requirements
Implementing a Mock Service
Using the Mock Service
Summary
9. Client-side Templating
Introducing Underscore.js
Using Underscore.js templates in our applications
Separating HTML templates from JavaScript code
Introducing Handlebars.js
Using Handlebars.js in our applications
Separating HTML templates from JavaScript code
Pre-compiling templates
Retrieving HTML templates asynchronously
Adopting it in an existing implementation
Moderation is best in all things
Summary
10. Plugin and Widget Development Patterns
Introducing jQuery Plugins
Following jQuery principles
Working on Composite Collection Objects
Allowing further chaining
Working with $.noConflict()
Wrapping with an IIFE
Creating reusable plugins
Accepting configuration parameters
Writing stateful jQuery plugins
Implementing a stateful jQuery Plugin
Destroying a plugin instance
Implementing getter and setter methods
Using our plugin in our Dashboard application
Using the jQuery Plugin Boilerplate
Adding methods to your plugin
Choosing a name
Summary
11. Optimization Patterns
Placing scripts near the end of the page
Bundling and minifying resources
Using IIFE parameters
Using CDNs
Using JSDelivr API
Optimizing common JavaScript code
Writing better for loops
Writing performant CSS selectors
Writing efficient jQuery code
Minimizing DOM traversals
Caching jQuery objects
Scoping element traversals
Chaining jQuery methods
Don't overdo it
Improving DOM manipulations
Creating DOM elements
Styling and animating
Manipulating detached elements
Introducing the Flyweight Pattern
Using Delegate Observers
Using $.noop()
Using the $.single plugin
Lazy Loading Modules
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜