So, how can we effect a (temporary) change in the core functionality of jQuery?
It all starts with the use of an Immediately Invoked Function Expression (IIFE); we then simply save a version of the original function before overriding it with our new function.
Note
You may have heard the term self-executing anonymous function being used; it is a misleading phrase, although it means the same thing as an IIFE, which is a more accurate description.
Let's see what the basic framework looks like in action:
(function($){ // store original reference to the method var _old = $.fn.method; $.fn.method = function(arg1,arg2){ if ( ... condition ... ) { return .... } else { // do the default return _old.apply(this,arguments); } }; })(jQuery);
If you were expecting something more complex, then I am sorry to disappoint you; there isn't a great deal of complexity required for a basic monkey patch! The extent of what goes into a patch...