AOC(面向切面编程)(?)

主要作用是把与核心业务逻辑模块无关的功能抽离出来,如日志统计、安全控制、异常处理等。把这些功能抽离出来之后,再通过“动态织入”的方式渗入业务逻辑模块中

Function.prototype.before = function(beforefn) {
    var __self = this;
    return function() {
        beforefn.apply(this, arguments);
        return __self.apply(this, arguments);
    };
}

Function.prototype.after = function(afterfn) {
    var __self = this;
    return function() {
        var ret = __self.apply(this, arguments);
        afterfn.apply(this, arguments);
        return ret;
    }
}

var func = function() {
    console.log(2);
}

func = func.before(function() {
    console.log(1);
}).after(function() {
    console.log(3);
});

func();

// 1
// 2
// 3

你可能感兴趣的:(AOC(面向切面编程)(?))