The question was about duck punching, which I first met on Paul Irelandβs blog. I get a general premise ... I keep a reference to an existing function, and then replace the existing function with a conditional branch, which will call a new function if the condition is met, or the old version if not. My question is: why should we use "apply" with 'this' as the first parameter when we call the _old function? I understand how to apply the work, but I'm looking for some clarification as to why this is necessary.
(function($){
var _old = $.fn.method;
$.fn.method = function(arg1,arg2){
if ( ... condition ... ) {
return ....
} else {
return _old.apply(this,arguments);
}
};
})(jQuery);
mike source
share