Created
December 12, 2009 00:35
-
-
Save isaacs/254637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function after (method, fn) { | |
var orig = this[method]; | |
if (orig === after || fn === after) throw new Error( | |
"That's not a good idea. Please don't be dumb." | |
); | |
this[method] = function aop_after () { | |
var ret = orig.apply(this, arguments); | |
var newArgs = Array.prototype.slice.call(arguments,0); | |
if (ret !== undefined) newArgs.concat(ret); | |
var nextRet = fn.apply(this, newArgs); | |
return (nextRet !== undefined) ? nextRet : ret; | |
}; | |
for (var i in orig) this[method][i] = orig[i]; | |
return this; | |
} | |
function before (method, fn) { | |
var orig = this[method]; | |
if (orig === before || fn === before) throw new Error( | |
"That's not a good idea. Please don't be dumb." | |
); | |
this[method] = function aop_before () { | |
var ret = fn.apply(this, arguments); | |
var newArgs = Array.prototype.slice.call(arguments,0); | |
if (ret !== undefined) newArgs.concat(ret); | |
var nextRet = orig.apply(this, newArgs); | |
return (nextRet !== undefined) ? nextRet : ret; | |
}; | |
for (var i in orig) this[method][i] = orig[i]; | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment