Created
August 22, 2013 11:53
-
-
Save fidel-karsto/6306243 to your computer and use it in GitHub Desktop.
Some basic AOP style functions.
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 before = function(fn, pre) { | |
return function() { | |
pre.apply(this, arguments); | |
return fn.apply(this, arguments); | |
}; | |
}, | |
after = function(fn, aft) { | |
return function() { | |
var result = fn.apply(this, arguments); | |
aft.apply(this, result); | |
return result; | |
}; | |
}, | |
around = function(fn, pre, aft) { | |
return function() { | |
var result; | |
pre.apply(this, arguments); | |
result = fn.apply(this, arguments); | |
aft.apply(this, result); | |
return result; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example
will result in