Skip to content

Instantly share code, notes, and snippets.

@edelabar
Created March 24, 2011 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edelabar/885501 to your computer and use it in GitHub Desktop.
Save edelabar/885501 to your computer and use it in GitHub Desktop.
var Aspect = Class.create();
Aspect.prototype = {
initialize: function( clazz, before, after ) {
var members = Object.keys( clazz.prototype );
members.each(
function( name ) {
if( Object.isFunction( clazz.prototype[name] ) ) {
var oldName = "old_" + name;
clazz.prototype[oldName] = clazz.prototype[name];
clazz.prototype[name] = function() {
if ( before ) before( name );
var me = this;
var args = $A( arguments );
args.each(
function( arg ) {
me[oldName] = me[oldName].curry( arg );
}
);
me[oldName]();
if( after ) after( name );
}
}
}
);
}
}
new Aspect( SampleClass, before, after );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment