Chapter 7. Expand your reach by extending jQuery

 

This chapter covers

  • Why to extend jQuery with custom code
  • Guidelines for effectively extending jQuery
  • Writing custom utility functions
  • Writing custom wrapper methods

Over the course of the previous chapters, we’ve seen that jQuery gives us a large toolset of useful methods and functions, and we’ve also seen that we can easily tie these tools together to give our pages whatever behavior we choose. Sometimes that code follows common patterns we want to use again and again. When such patterns emerge, it makes sense to capture these repeated operations as reusable tools that we can add to our original toolset. In this chapter, we’ll explore how to capture these reusable fragments of code as extensions to jQuery.

But before any of that, let’s discuss why we’d want to pattern our own code as extensions to jQuery in the first place.

7.1. Why extend jQuery?

If you’ve been paying attention while reading through this book, and you’ve been reviewing the code examples presented within it, you undoubtedly will have noted that adopting jQuery for use in our pages has a profound effect on how script is written within a page.

7.2. The jQuery plugin authoring guidelines

7.3. Writing custom utility functions

7.4. Adding new wrapper methods

7.5. Summary