Monmonja Programming Blog

July 9, 2008

Intercept a function in javascript

Filed under: Programming — Tags: , — admin @ 10:39 am

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

Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • del.icio.us
  • StumbleUpon
  • TwitThis
  • Fark
  • Facebook
  • Technorati
  • Sphinn
  • Furl
  • Google Bookmarks
  • Mixx

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Monmonja Programming Blog is Digg proof thanks to caching by WP Super Cache