CHAPTER 6Chaining
In this chapter we look at JavaScript's ability to chain methods together. By using a few simple techniques, application developers can streamline their code authoring. As well as writing time-saving functions that reduce the burden of common tasks, you can improve how code is implemented. In the end, you can write an entire JavaScript library that embraces the technique of chaining, and chains together all your favorite methods.
Chaining is really just a syntax hack. It allows you to express complex operations in a small amount of code by reusing an initial operation. Chaining requires two parts: a factory that creates an object around an HTML element (we cover factories in depth in Chapter 7), and methods that perform some ...
Get Pro JavaScript™ Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.