//for AOP
function _after(target, methodName, aspect) {
var method = target[methodName];
//overwrite the method.
target[methodName] = function () {
var args = Array.prototype.slice.call(arguments),
result;
result = method.apply(this, arguments);
args.push(result);
args.push({
target: this,
methodName: methodName,
method: method
});
return aspect.apply(this, args);
};
}
function _apply(func, target, methodNames, aspect) {
if (Object.prototype.toString.call(methodNames) !== '[object Array]') {
methodNames = [methodNames];
}
var i = 0, mName;
for (; mName = methodNames[i]; i++) {
func(target, mName, aspect);
}
}
function after(target, methodNames, aspect) {
_apply(_after, target, methodNames, aspect);
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme