Where The Streets Have No Name

Event.observeMethod: More AOP for JavaScript 본문

Developement/Web

Event.observeMethod: More AOP for JavaScript

highheat 2007. 6. 4. 08:27
http://___.constantology.com/observe_method/

Christos Constandinou has created Event.observeMethod ,a library that gives you a way of adding event listeners to methods inan object and running other methods before, around and/ or after themethod 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 itsconnect() model. You tend to wonder how often people need thisgranularity versus just being able to attach normal events.

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