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);** //这一块不是应该输出2么   
            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 . 但为啥不是 12 23, 因为Function.prototype.after里面第一步就是 _self.apply() ?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
稍微改一下,看你看得懂不