/*
*  AOP切面方法注入
*/
function Aspects() { }
//target:被织入的对象, method:织入的方法的名字, advice:通知函数
Aspects.prototype = {
    before: function(target, method, advice) {
        var original = target[method];
        var events = [];
        if (arguments.length >= 2) {
            for (var i = 2; i < arguments.length; i++) {
                events.push(arguments[i]);
            }
        }
        target[method] = function() {
            for (var i = 0; i < events.length; i++) {
                events[i]();
            }
            original.apply(target, arguments);
        };
    },
    after: function(target, method, advice) {
        var original = target[method];
        var events = [];
        if (arguments.length >= 2) {
            for (var i = 2; i < arguments.length; i++) {
                events.push(arguments[i]);
            }
        }
        target[method] = function() {
            original.apply(target, arguments);
            for (var i = 0; i < events.length; i++) {
                events[i]();
            }
        };
    }
};