Now that we've seen some examples in action, it's worth taking a moment to consider some of the risks of monkey patching libraries, such as jQuery:
The principle risk and one that is likely to cause the most trouble is clashing. Imagine that you've created a patch that contains some functions—we'll call these functions
1
,2
, and3
. Add another patch, and it is essential that we do not use the same function names; otherwise, it's difficult to determine whether function1
, or2
, or even3
comes first?Another risk is security. If a library such as jQuery can be monkey patched, what is to stop anyone from introducing malicious constructs that damage the existing code? One can argue that this risk is always present in client-side scripting; the risk is greater when you override core jQuery functionality, compared to a standard plugin.
There is always a risk that an upgrade to the core library may introduce a change that not only breaks your patch but...