Christos Constandinou has created Event.observeMethod, a library that gives you a way of adding event listeners to methods in an object and running other methods before, around and/ or after the method you are listening to.

The code itself is small, based on Prototype, and only 49 lines (1.8kb), uncompressed.

JAVASCRIPT:

  1.  
  2. Event.observeMethod( window, ‘myNewFunc’, myBeforeFunc, Event.BEFORE );
  3. Event.observeMethod( Friend, “initialize”, this.addBirthday.bind( this ) );
  4.  

Dojo has allowed you to do this kind of thing in its connect() model. You tend to wonder how often people need this granularity versus just being able to attach normal events.

It makes a lot of sense in large scale applications, but maybe not your JS hacking?

Source: Ajaxian
Original Article: http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript

Leave a Reply

You must be logged in to post a comment.



Site Navigation