Created
March 24, 2011 17:41
-
-
Save edelabar/885501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} | |
} | |
} | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Aspect( SampleClass, before, after ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment