Okay, so we've seen what a typical patch will look like; the question, though, is, why would we want to patch the core library functionality using this method?
This is a very good question—it's a method that has its risks (as we will see later in this chapter, in the Considering the pitfalls of monkey patching section). The key to using this method is to take a considered approach; with this in mind, let's take a moment to consider the benefits of duck punching jQuery:
We can replace methods, attributes, or functions at runtime, where they lack functionality or contain a bug that needs to be fixed and we can't wait for an official patch
Duck punching jQuery allows you to modify or extend the existing behavior of jQuery without maintaining a private copy of the source code
We have the safety net of being able to apply a patch to objects running in memory, instead of the source code; in other words, if it goes completely wrong, we can simply pull the...