标签:turn on() type 原理 ref fun arguments 实现 prototype
javascript实现aop的基本实现原理
        Function.prototype.before = function(beforefn){
            var _this = this; //  记录原函数的引用
            return function(){
                beforefn.apply(this, arguments);
                return _this.apply(this, arguments);
            }
        }
        Function.prototype.after = function(afterfn){
            var _this = this;
            return function(){
                var ret = _this.apply(this, arguments);
                afterfn.apply(this, arguments);
                return ret;
            }
        }
        var fun = function(){
            console.log("我是测试函数");
        }
        fun = fun.before(function(){
            console.log("之前执行");
        }).after(function(){
            console.log("之后执行");
        })
        fun();标签:turn on() type 原理 ref fun arguments 实现 prototype
原文地址:https://www.cnblogs.com/cyrus-br/p/10436521.html