I had been trying to make a function that will intercept another function but i failed so finally i gave up and instead of making my own i decided to use AOP plugin for jQuery. The download page is at google code http://code.google.com/p/jquery-aop/. AOP is Aspect Oriented Programming, for more info, Here is the wikipedia page.
What the use? For example you used a component build by other people and you dont want to mess up their code then the AOP pluglin is for you. Say you have a jquery datepicker component, and every time the user click on the a date (_setdate function) of this component you want do something fancy. Then you can do this:
jQuery.aop.before( {target: jQuery.datepicker, method: '_selectDay'},
function() {
alert("Do something fancy before this function call");
}
);
or it after the call
jQuery.aop.after( {target: jQuery.datepicker, method: '_selectDay'},
function() {
alert("Do something fancy after this function call");
}
);
There are a lot of feature on this plugin, you can refer to the documentation for the others.
http://code.google.com/p/jquery-aop/wiki/Reference